1
0
mirror of https://gitlab.com/Deukhoofd/DeukBot4.git synced 2026-04-03 11:10:05 +00:00

Made reserved tags check permissions, fixed ulong to/from string differences breaking tags

This commit is contained in:
2018-08-25 17:28:09 +02:00
parent d2d6b7824f
commit b849c1b734
2 changed files with 44 additions and 28 deletions

View File

@@ -8,7 +8,7 @@ namespace DeukBot4.Database
public class ReminderHandler
{
public static ReminderHandler Main = new ReminderHandler();
public static ConnectionMultiplexer Redis = ConnectionMultiplexer.Connect("127.0.0.1");
public static ConnectionMultiplexer Redis = ConnectionMultiplexer.Connect("localhost:6379");
public async Task AddReminder(TimeSpan time, string message, ulong channel, ulong author, ulong recipient)
@@ -21,10 +21,10 @@ namespace DeukBot4.Database
db.SortedSetAddAsync("deukbot_reminders", (RedisValue)id, expectedTime.ToBinary());
db.HashSetAsync((RedisKey) id, new[]
{
new HashEntry("channel", channel.ToString()),
new HashEntry("channel", channel.ToString("D")),
new HashEntry("message", message),
new HashEntry("author", author.ToString()),
new HashEntry("recipient", recipient.ToString()),
new HashEntry("author", author.ToString("D")),
new HashEntry("recipient", recipient.ToString("D")),
});
}
catch (Exception e)
@@ -36,34 +36,42 @@ namespace DeukBot4.Database
public async Task CheckReminders()
{
var checkTime = TimeSpan.FromSeconds(70);
var startTime = DateTime.UtcNow;
var desiredTopScore = (startTime + checkTime).ToBinary();
var db = Redis.GetDatabase();
var reminders = db.SortedSetRangeByScoreWithScores("deukbot_reminders", stop: desiredTopScore);
foreach (var sortedSetEntry in reminders)
try
{
var val = sortedSetEntry.Element.ToString();
var timeLong = sortedSetEntry.Score;
var time = DateTime.FromBinary((long) timeLong);
var data = db.HashGetAll(val);
ulong channel = 0;
ulong author = 0;
ulong recipient = 0;
string message = null;
foreach (var hashEntry in data)
var startTime = DateTime.UtcNow;
var desiredTopScore = (startTime + checkTime).ToBinary();
var db = Redis.GetDatabase();
var reminders = db.SortedSetRangeByScoreWithScores("deukbot_reminders", start: Double.MinValue,
stop: desiredTopScore);
foreach (var sortedSetEntry in reminders)
{
if (hashEntry.Name == "channel") channel = ulong.Parse(hashEntry.Value);
else if (hashEntry.Name == "message") message = hashEntry.Value;
else if (hashEntry.Name == "author") author = ulong.Parse(hashEntry.Value);
else if (hashEntry.Name == "recipient") recipient = ulong.Parse(hashEntry.Value);
var val = sortedSetEntry.Element.ToString();
var timeLong = sortedSetEntry.Score;
var time = DateTime.FromBinary((long) timeLong);
var data = db.HashGetAll(val);
ulong channel = 0;
ulong author = 0;
ulong recipient = 0;
string message = null;
foreach (var hashEntry in data)
{
if (hashEntry.Name == "channel") channel = ulong.Parse(hashEntry.Value);
else if (hashEntry.Name == "message") message = hashEntry.Value;
else if (hashEntry.Name == "author") author = ulong.Parse(hashEntry.Value);
else if (hashEntry.Name == "recipient") recipient = ulong.Parse(hashEntry.Value);
}
var diff = time - DateTime.UtcNow;
FireReminderAtTime((int) diff.TotalSeconds, channel, message, author, recipient);
db.KeyDelete(val);
}
var diff = time - DateTime.UtcNow;
FireReminderAtTime((int) diff.TotalSeconds, channel, message, author, recipient);
db.KeyDelete(val);
db.SortedSetRemoveRangeByScoreAsync("deukbot_reminders", Double.MinValue, desiredTopScore);
}
catch (Exception e)
{
Logger.Main.LogError(e);
}
db.SortedSetRemoveRangeByScoreAsync("deukbot_reminders", Double.MinValue, desiredTopScore);
await Task.Delay(checkTime);
await CheckReminders();
}