amki
5 years ago
12 changed files with 197 additions and 161 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,95 @@ |
|||
using Discord.WebSocket; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using System.Timers; |
|||
|
|||
namespace DiscoBot.gsmeet |
|||
{ |
|||
public class GSMeetingTimers |
|||
{ |
|||
private List<TimeSpan> WarningTimes = new List<TimeSpan> { |
|||
new TimeSpan(2, 0, 0, 0), |
|||
new TimeSpan(1, 0, 0, 0) }; |
|||
private List<TimeSpan> UserTimes = new List<TimeSpan> { |
|||
new TimeSpan(7, 0, 0, 0), |
|||
new TimeSpan(6, 0, 0, 0), |
|||
new TimeSpan(5, 0, 0, 0), |
|||
new TimeSpan(4, 0, 0, 0), |
|||
new TimeSpan(3, 0, 0, 0) }; |
|||
private Dictionary<DateTimeOffset, GSEventTimers> events = new Dictionary<DateTimeOffset, GSEventTimers>(); |
|||
public GSMeetingTimers() |
|||
{ |
|||
} |
|||
public void UpdateTimers(SocketTextChannel chan, GSMeeting meeting) |
|||
{ |
|||
for(var i=0;i<meeting.Dates.Count;++i) |
|||
{ |
|||
var date = meeting.Dates[i]; |
|||
// Keep this so we can use it to pick from user.Signups later! (async)
|
|||
var idx = i; |
|||
GSEventTimers evt; |
|||
if(events.ContainsKey(date)) |
|||
{ |
|||
evt = events[date]; |
|||
} else |
|||
{ |
|||
evt = new GSEventTimers(); |
|||
events.Add(date, evt); |
|||
} |
|||
|
|||
foreach(var t in evt.UserTimers) |
|||
{ |
|||
t.Dispose(); |
|||
} |
|||
|
|||
evt.UserTimers = new List<Timer>(); |
|||
|
|||
foreach(var ts in UserTimes) |
|||
{ |
|||
var when = date - ts; |
|||
if(when < DateTimeOffset.Now) |
|||
{ |
|||
continue; |
|||
} |
|||
Console.WriteLine("Setting a timer for " + when + " for evt " + date); |
|||
var whents = when - DateTimeOffset.Now; |
|||
// Debug resolve timers after 30s
|
|||
//Timer t = new Timer(new TimeSpan(0, 0, 30).TotalMilliseconds);
|
|||
Timer t = new Timer(whents.TotalMilliseconds); |
|||
t.AutoReset = false; |
|||
var users = meeting.Users; |
|||
t.Elapsed += async (sender, e) => |
|||
{ |
|||
foreach(var user in users) |
|||
{ |
|||
if(user.Signups[idx] != "1" && user.Signups[idx] != "0" && user.Signups[idx] != "0.5") |
|||
{ |
|||
if(user.User != null) { |
|||
await chan.SendMessageAsync("Hey " + user.User.Mention + " could you please sign up for our raid on " + date + "?"); |
|||
} else |
|||
{ |
|||
await chan.SendMessageAsync("Hey " + user.Name + " could you please sign up for our raid on " + date + "?"); |
|||
} |
|||
} |
|||
} |
|||
}; |
|||
t.Start(); |
|||
evt.UserTimers.Add(t); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class GSEventTimers |
|||
{ |
|||
public GSEventTimers() |
|||
{ |
|||
this.UserTimers = new List<Timer>(); |
|||
this.WarningTimers = new List<Timer>(); |
|||
} |
|||
public List<Timer> UserTimers { get; set; } |
|||
public List<Timer> WarningTimers { get; set; } |
|||
} |
|||
} |
Loading…
Reference in new issue