mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-21 13:54:36 +00:00
Update remaining handlers to not use guild cache
This commit is contained in:
parent
23dd15d741
commit
3d3db6d5e1
2 changed files with 19 additions and 19 deletions
|
@ -1,4 +1,5 @@
|
||||||
using Discord;
|
using BirthdayBot.Data;
|
||||||
|
using Discord;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -89,13 +90,13 @@ namespace BirthdayBot.UserInterface
|
||||||
return (helpRegular.Build(), helpConfig.Build());
|
return (helpRegular.Build(), helpConfig.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CmdHelp(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
private async Task CmdHelp(string[] param, GuildConfiguration gconf, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
||||||
=> await reqChannel.SendMessageAsync(embed: _helpEmbed);
|
=> await reqChannel.SendMessageAsync(embed: _helpEmbed);
|
||||||
|
|
||||||
private async Task CmdHelpConfig(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
private async Task CmdHelpConfig(string[] param, GuildConfiguration gconf, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
||||||
=> await reqChannel.SendMessageAsync(embed: _helpConfigEmbed);
|
=> await reqChannel.SendMessageAsync(embed: _helpConfigEmbed);
|
||||||
|
|
||||||
private async Task CmdHelpTzdata(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
private async Task CmdHelpTzdata(string[] param, GuildConfiguration gconf, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
||||||
{
|
{
|
||||||
const string tzhelp = "You may specify a time zone in order to have your birthday recognized with respect to your local time. "
|
const string tzhelp = "You may specify a time zone in order to have your birthday recognized with respect to your local time. "
|
||||||
+ "This bot only accepts zone names from the IANA Time Zone Database (a.k.a. Olson Database).\n\n"
|
+ "This bot only accepts zone names from the IANA Time Zone Database (a.k.a. Olson Database).\n\n"
|
||||||
|
@ -110,7 +111,7 @@ namespace BirthdayBot.UserInterface
|
||||||
await reqChannel.SendMessageAsync(embed: embed.Build());
|
await reqChannel.SendMessageAsync(embed: embed.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CmdHelpMessage(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
private async Task CmdHelpMessage(string[] param, GuildConfiguration gconf, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
||||||
{
|
{
|
||||||
const string msghelp = "The `message` and `messagepl` subcommands allow for editing the message sent into the announcement "
|
const string msghelp = "The `message` and `messagepl` subcommands allow for editing the message sent into the announcement "
|
||||||
+ "channel (defined with `{0}config channel`). This feature is separated across two commands:\n"
|
+ "channel (defined with `{0}config channel`). This feature is separated across two commands:\n"
|
||||||
|
@ -136,7 +137,7 @@ namespace BirthdayBot.UserInterface
|
||||||
await reqChannel.SendMessageAsync(embed: embed.Build());
|
await reqChannel.SendMessageAsync(embed: embed.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CmdInfo(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
private async Task CmdInfo(string[] param, GuildConfiguration gconf, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
||||||
{
|
{
|
||||||
var strStats = new StringBuilder();
|
var strStats = new StringBuilder();
|
||||||
var asmnm = System.Reflection.Assembly.GetExecutingAssembly().GetName();
|
var asmnm = System.Reflection.Assembly.GetExecutingAssembly().GetName();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using Discord.WebSocket;
|
using BirthdayBot.Data;
|
||||||
|
using Discord.WebSocket;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ namespace BirthdayBot.UserInterface
|
||||||
new CommandDocumentation(new string[] { "remove" }, "Removes your birthday information from this bot.", null);
|
new CommandDocumentation(new string[] { "remove" }, "Removes your birthday information from this bot.", null);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private async Task CmdSet(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
private async Task CmdSet(string[] param, GuildConfiguration gconf, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
||||||
{
|
{
|
||||||
// Requires one parameter. Optionally two.
|
// Requires one parameter. Optionally two.
|
||||||
if (param.Length < 2 || param.Length > 3)
|
if (param.Length < 2 || param.Length > 3)
|
||||||
|
@ -140,9 +140,9 @@ namespace BirthdayBot.UserInterface
|
||||||
bool known; // Extra detail: Bot's response changes if the user was previously unknown.
|
bool known; // Extra detail: Bot's response changes if the user was previously unknown.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var user = Instance.GuildCache[reqChannel.Guild.Id].GetUser(reqUser.Id);
|
var user = await GuildUserConfiguration.LoadAsync(gconf.GuildId, reqUser.Id);
|
||||||
known = user.IsKnown;
|
known = user.IsKnown;
|
||||||
await user.UpdateAsync(bmonth, bday, btz, BotConfig.DatabaseSettings);
|
await user.UpdateAsync(bmonth, bday, btz);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -161,7 +161,7 @@ namespace BirthdayBot.UserInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CmdZone(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
private async Task CmdZone(string[] param, GuildConfiguration gconf, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
||||||
{
|
{
|
||||||
if (param.Length != 2)
|
if (param.Length != 2)
|
||||||
{
|
{
|
||||||
|
@ -169,7 +169,7 @@ namespace BirthdayBot.UserInterface
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = Instance.GuildCache[reqChannel.Guild.Id].GetUser(reqUser.Id);
|
var user = await GuildUserConfiguration.LoadAsync(gconf.GuildId, reqUser.Id);
|
||||||
if (!user.IsKnown)
|
if (!user.IsKnown)
|
||||||
{
|
{
|
||||||
await reqChannel.SendMessageAsync(":x: You may only update your time zone when you have a birthday registered."
|
await reqChannel.SendMessageAsync(":x: You may only update your time zone when you have a birthday registered."
|
||||||
|
@ -187,12 +187,12 @@ namespace BirthdayBot.UserInterface
|
||||||
reqChannel.SendMessageAsync(ex.Message, embed: DocZone.UsageEmbed).Wait();
|
reqChannel.SendMessageAsync(ex.Message, embed: DocZone.UsageEmbed).Wait();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await user.UpdateAsync(user.BirthMonth, user.BirthDay, btz, BotConfig.DatabaseSettings);
|
await user.UpdateAsync(user.BirthMonth, user.BirthDay, btz);
|
||||||
|
|
||||||
await reqChannel.SendMessageAsync($":white_check_mark: Your time zone has been updated to **{btz}**.");
|
await reqChannel.SendMessageAsync($":white_check_mark: Your time zone has been updated to **{btz}**.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CmdRemove(string[] param, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
private async Task CmdRemove(string[] param, GuildConfiguration gconf, SocketTextChannel reqChannel, SocketGuildUser reqUser)
|
||||||
{
|
{
|
||||||
// Parameter count check
|
// Parameter count check
|
||||||
if (param.Length != 1)
|
if (param.Length != 1)
|
||||||
|
@ -203,10 +203,9 @@ namespace BirthdayBot.UserInterface
|
||||||
|
|
||||||
// Extra detail: Send a notification if the user isn't actually known by the bot.
|
// Extra detail: Send a notification if the user isn't actually known by the bot.
|
||||||
bool known;
|
bool known;
|
||||||
var g = Instance.GuildCache[reqChannel.Guild.Id];
|
var u = await GuildUserConfiguration.LoadAsync(gconf.GuildId, reqUser.Id);
|
||||||
known = g.GetUser(reqUser.Id).IsKnown;
|
known = u.IsKnown;
|
||||||
// Delete database and cache entry
|
await u.DeleteAsync();
|
||||||
await g.DeleteUserAsync(reqUser.Id);
|
|
||||||
if (!known)
|
if (!known)
|
||||||
{
|
{
|
||||||
await reqChannel.SendMessageAsync(":white_check_mark: This bot already does not contain your information.");
|
await reqChannel.SendMessageAsync(":white_check_mark: This bot already does not contain your information.");
|
||||||
|
|
Loading…
Reference in a new issue