Browse Source

Fix BDayGreet and GSMeet outputs

master
amki 5 years ago
parent
commit
f0c7c99627
  1. BIN
      DiscoBot/299585558710190101-bdaygreet.db
  2. BIN
      DiscoBot/299585558710190101-calendar.db
  3. BIN
      DiscoBot/299585558710190101-gsmeet.db
  4. BIN
      DiscoBot/299585558710190101-rss.db
  5. BIN
      DiscoBot/615631052047908870-gsmeet.db
  6. BIN
      DiscoBot/98293701175955456-bdaygreet.db
  7. BIN
      DiscoBot/98293701175955456-calendar.db
  8. BIN
      DiscoBot/98293701175955456-gsmeet.db
  9. BIN
      DiscoBot/98293701175955456-rss.db
  10. 2
      DiscoBot/DisBot.cs
  11. 17
      DiscoBot/IModule.cs
  12. 34
      DiscoBot/bdaygreet/BDayGreet.cs
  13. 86
      DiscoBot/gsmeet/GSMeet.cs
  14. 4
      DiscoBot/gsmeet/GSMeetContext.cs
  15. 8
      DiscoBot/rss/Rss.cs

BIN
DiscoBot/299585558710190101-bdaygreet.db

Binary file not shown.

BIN
DiscoBot/299585558710190101-calendar.db

Binary file not shown.

BIN
DiscoBot/299585558710190101-gsmeet.db

Binary file not shown.

BIN
DiscoBot/299585558710190101-rss.db

Binary file not shown.

BIN
DiscoBot/615631052047908870-gsmeet.db

Binary file not shown.

BIN
DiscoBot/98293701175955456-bdaygreet.db

Binary file not shown.

BIN
DiscoBot/98293701175955456-calendar.db

Binary file not shown.

BIN
DiscoBot/98293701175955456-gsmeet.db

Binary file not shown.

BIN
DiscoBot/98293701175955456-rss.db

Binary file not shown.

2
DiscoBot/DisBot.cs

@ -191,7 +191,7 @@ namespace DiscoBot
if(commands.ContainsKey(command))
commands[command](message, splits);
else
message.Channel.SendMessageAsync("Command not found!");
Console.WriteLine("Command not found!");
});
} else
{

17
DiscoBot/IModule.cs

@ -13,5 +13,22 @@ namespace DiscoBot
string Name { get; set; }
void Initialize();
Task OnNewWebSocketAsync(WebSocket ws, TaskCompletionSource<object> tcs);
string ConcatParameters(string[] parameters)
{
string str = "";
for (var i = 0; i < parameters.Length; ++i)
{
var s = parameters[i];
if (str == "")
{
str += s;
}
else
{
str += " " + s;
}
}
return str;
}
}
}

34
DiscoBot/bdaygreet/BDayGreet.cs

@ -48,7 +48,13 @@ namespace DiscoBot.bdaygreet
updateTimer.AutoReset = false;
updateTimer.Elapsed += async (sender, e) =>
{
await Task.Run(() => HandleBDayCheck());
try
{
await Task.Run(() => HandleBDayCheck());
} catch(Exception)
{
Console.WriteLine("bday: EXCEPTION IN BDAY CHECK");
}
};
updateTimer.Start();
}
@ -117,20 +123,18 @@ namespace DiscoBot.bdaygreet
var gchan = msg.Channel as IGuildChannel;
string name = parameters[1];
string date = parameters[2];
SocketGuildUser user;
try
{
user = guild.Users.Where(u => u.Mention == name).Single();
}
catch (InvalidOperationException)
try {
var id = MentionUtils.ParseUser(name);
user = guild.Users.Where(u => u.Id == id).Single();
} catch(Exception)
{
await msg.Channel.SendMessageAsync("I can't find user " + name + " so I can't add them.");
return;
}
DateTimeOffset d;
try {
d = DateTimeOffset.ParseExact(date,new string[] { "dd.MM.", "d.MM", "dd.M", "d.M." }, null, DateTimeStyles.AssumeUniversal);
d = DateTimeOffset.ParseExact(date,new string[] { "dd.MM.", "d.MM.", "dd.M", "d.M." }, null, DateTimeStyles.AssumeUniversal);
} catch(FormatException) {
await msg.Channel.SendMessageAsync("Sorry I can't parse your date. Please try again!");
return;
@ -203,7 +207,7 @@ namespace DiscoBot.bdaygreet
return;
}
var gchan = msg.Channel as IGuildChannel;
string tag = parameters[1];
string tag = ((IModule)this).ConcatParameters(parameters[1..]);
try
{
var b = bdayGreetContext.BDays.Where(b => b.DiscordTag == tag).Single();
@ -216,12 +220,14 @@ namespace DiscoBot.bdaygreet
}
}
private Task HandleBDayDebugCommand(SocketMessage msg, string[] parameters)
private async Task HandleBDayDebugCommand(SocketMessage msg, string[] parameters)
{
Console.WriteLine("Handling test command!");
string para = string.Join(",", parameters);
msg.Channel.SendMessageAsync("Test succeeded. Params: "+para);
return Task.CompletedTask;
await msg.Channel.SendMessageAsync("DEBUG!");
string name = parameters[1];
var id = MentionUtils.ParseUser(name);
var user = guild.Users.Where(u => u.Id == id).Single();
await msg.Channel.SendMessageAsync("name: " + name);
await msg.Channel.SendMessageAsync("Found user with id" + user.Id+" and mention "+user.Mention+" Username: "+user.Username+" Discriminator: "+user.Discriminator+" DiscriminiatorValue: "+user.DiscriminatorValue);
}
public void Initialize()

86
DiscoBot/gsmeet/GSMeet.cs

@ -32,7 +32,7 @@ namespace DiscoBot.gsmeet
private static readonly string ApplicationName = "DiscoBot";
private SheetsService service;
private Dictionary<string, GSMeetingTimers> meetingTimers = new Dictionary<string, GSMeetingTimers>();
private List<GSMeeting> lastMeetings = null;
@ -73,7 +73,13 @@ namespace DiscoBot.gsmeet
timer.AutoReset = true;
timer.Elapsed += async (sender, e) =>
{
await Task.Run(() => HandleSheetCheck(sheet));
try
{
await Task.Run(() => HandleSheetCheck(sheet));
} catch(Exception ex)
{
Console.WriteLine("gsmeet: EXCEPTION IN SHEET CHECK"+ex);
}
};
timer.Start();
timers.Add(sheet.Db.Name, timer);
@ -133,6 +139,7 @@ namespace DiscoBot.gsmeet
var binHash = sha1.ComputeHash(Encoding.ASCII.GetBytes(idString));
var hash = BitConverter.ToString(binHash).Replace("-", string.Empty);
meeting.Id = hash;
meeting.FetchTime = DateTimeOffset.Now;
return meeting;
}
@ -167,6 +174,40 @@ namespace DiscoBot.gsmeet
return meetings;
}
private string MissingStringForEvent(GSMeeting m)
{
var now = DateTimeOffset.Now;
string s = "";
for(var i=0;i<m.Dates.Count;++i)
{
var date = m.Dates[i];
if(date < now || date > now.AddDays(7))
{
continue;
}
var us = "";
foreach (var user in m.Users)
{
if (user.Signups[i] != "1" && user.Signups[i] != "0" && user.Signups[i] != "0.5")
{
if (user.User != null)
{
us = user.User.Mention + " ";
}
else
{
us += user.Name + " ";
}
}
}
if(us != "")
{
s += date + ": "+ us + "\n";
}
}
return s;
}
private async Task HandleSheetCheck(GSSheet sheet)
{
SocketTextChannel c = guild.Channels.Where(g => g.Id == sheet.Db.Channel).Single() as SocketTextChannel;
@ -176,7 +217,33 @@ namespace DiscoBot.gsmeet
{
Console.WriteLine("No values found.");
}
var meetings = await ParseGSMeetSheet(sheet, values);
lastMeetings = await ParseGSMeetSheet(sheet, values);
var ln = sheet.Db.LastNotified;
var now = DateTimeOffset.Now;
if(ln.AddDays(1) > now)
{
Console.WriteLine("It is: "+now+" Next notify is: " + ln.AddDays(1));
return;
}
Console.WriteLine("Notifying...");
string missStr = "";
foreach(var meeting in lastMeetings)
{
missStr += MissingStringForEvent(meeting);
}
if(!string.IsNullOrEmpty(missStr))
{
string msg = "Heyo! I found the following missing raid signups:\n";
msg += missStr;
msg += "Please sign up so we can raid! :)";
await c.SendMessageAsync(msg);
}
//TODO FIXME: Remove the hardcode 18 and read meeting timespan from sheet and use this value
var nextDate = now.AddHours(-now.Hour + 18).AddMinutes(-now.Minute).AddSeconds(-now.Second).AddMilliseconds(-now.Millisecond);
Console.WriteLine("Setting next notify to: " + nextDate);
sheet.Db.LastNotified = nextDate;
gsmeetContext.SaveChanges();
/*
foreach(var meeting in meetings)
{
if(!sheet.Timers.ContainsKey(meeting.Id))
@ -187,17 +254,6 @@ namespace DiscoBot.gsmeet
sheet.Timers[meeting.Id].UpdateTimers(c, meeting);
}
Console.WriteLine("Parsed sheet " + sheet.Db.Id);
/*
var str = "";
foreach (var row in values)
{
foreach (var col in row)
{
str += col + "| ";
}
str += "\n";
}
c.SendMessageAsync("Result: " + str);
*/
}
@ -216,6 +272,8 @@ namespace DiscoBot.gsmeet
sheet.Id = sheetId;
sheet.SheetName = sheetName;
sheet.LastChecked = DateTimeOffset.Now;
var now = DateTimeOffset.Now;
sheet.LastNotified = now.AddDays(-1).AddHours(-now.Hour).AddMinutes(-now.Minute).AddSeconds(-now.Second).AddMilliseconds(-now.Millisecond);
sheet.CheckInterval = new TimeSpan(0, 0, timeSec);
gsmeetContext.GSheets.Add(sheet);
try

4
DiscoBot/gsmeet/GSMeetContext.cs

@ -35,6 +35,7 @@ namespace DiscoBot.gsmeet
public ulong Channel { get; set; }
public TimeSpan CheckInterval { get; set; }
public DateTimeOffset LastChecked { get; set; }
public DateTimeOffset LastNotified { get; set; }
}
public class GSSheet
@ -42,10 +43,8 @@ namespace DiscoBot.gsmeet
public GSSheet(DBSheet db)
{
this.Db = db;
this.Timers = new Dictionary<string, GSMeetingTimers>();
}
public DBSheet Db { get; set; }
public Dictionary<string, GSMeetingTimers> Timers { get; set; }
}
public class GSMeetingUser
@ -68,6 +67,7 @@ namespace DiscoBot.gsmeet
this.Dates = new List<DateTimeOffset>();
}
public string Id { get; set; }
public DateTimeOffset FetchTime { get; set; }
public List<GSMeetingUser> Users { get; set; }
public List<DateTimeOffset> Dates { get; set; }
}

8
DiscoBot/rss/Rss.cs

@ -45,7 +45,13 @@ namespace DiscoBot.rss
timer.AutoReset = true;
timer.Elapsed += async (sender, e) =>
{
await Task.Run(() => HandleFeedCheck(feed));
try
{
await Task.Run(() => HandleFeedCheck(feed));
} catch(Exception)
{
Console.WriteLine("rss: EXCEPTION IN FEED READ!");
}
};
timer.Start();
timers.Add(feed.Name, timer);

Loading…
Cancel
Save