1
0
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:
2019-01-29 14:28:47 +01:00
parent 67e793de47
commit 7b4967f1ca
6 changed files with 237 additions and 1 deletions

View File

@@ -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;
}

View 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;
}
}
}
}