mirror of
https://gitlab.com/Deukhoofd/DeukBot4.git
synced 2026-04-03 11:10:05 +00:00
Added system to give/take points from users per server, added new joke controller that removes points from users if they say owo, uwu, etc
This commit is contained in:
@@ -19,7 +19,11 @@ namespace DeukBot4.Database
|
||||
DateTime bday = DateTime.MinValue;
|
||||
foreach (var bdayEntry in bdayEntries)
|
||||
{
|
||||
if (bdayEntry.Name == "birthday") bday = DateTime.FromBinary(long.Parse(bdayEntry.Value));
|
||||
if (bdayEntry.Name == "birthday")
|
||||
{
|
||||
bday = DateTime.FromBinary(long.Parse(bdayEntry.Value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bday;
|
||||
}
|
||||
|
||||
58
DeukBot4/Database/PointHandler.cs
Normal file
58
DeukBot4/Database/PointHandler.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace DeukBot4.Database
|
||||
{
|
||||
public static class PointHandler
|
||||
{
|
||||
public static async Task<long?> GetPoints(ulong serverId, ulong userId)
|
||||
{
|
||||
var key = $"{serverId:D}-{userId:D}";
|
||||
try
|
||||
{
|
||||
var db = ReminderHandler.Redis.GetDatabase();
|
||||
var exists = db.HashGet("points", (RedisValue) key);
|
||||
if (!exists.HasValue)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
var points = long.Parse(exists);
|
||||
return points;
|
||||
}
|
||||
catch ( Exception e)
|
||||
{
|
||||
Logger.Main.LogError(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<long?> ChangePoints(ulong serverId, ulong userId, long deltaPoints)
|
||||
{
|
||||
var key = $"{serverId:D}-{userId:D}";
|
||||
try
|
||||
{
|
||||
var db = ReminderHandler.Redis.GetDatabase();
|
||||
var exists = db.HashGet("points", (RedisValue) key);
|
||||
if (!exists.HasValue)
|
||||
{
|
||||
db.HashSet("points", (RedisValue) key, deltaPoints);
|
||||
return deltaPoints;
|
||||
}
|
||||
|
||||
var points = long.Parse(exists);
|
||||
|
||||
points += deltaPoints;
|
||||
if (points < -100)
|
||||
points = -100;
|
||||
db.HashSet("points", (RedisValue) key, points);
|
||||
return points;
|
||||
}
|
||||
catch ( Exception e)
|
||||
{
|
||||
Logger.Main.LogError(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user