This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventHandler.cs
124 lines (100 loc) · 5.42 KB
/
EventHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using Discord;
using Discord.Commands;
using System.Reflection;
using Discord.WebSocket;
using System.Threading.Tasks;
using TimeBot.Interactions;
using TimeBot.UserData;
namespace TimeBot
{
public static class EventHandler
{
public static DiscordSocketClient _socketClient;
public static CommandService _service;
public static async Task InitializeAsync(DiscordSocketClient socketClient)
{
_socketClient = socketClient;
_service = new CommandService();
await _service.AddModulesAsync(Assembly.GetEntryAssembly(), null);
_socketClient.MessageReceived += HandleCommandAsync;
_service.Log += Log;
_socketClient.InteractionCreated += OnInteractionCreated;
}
private static async Task OnInteractionCreated(SocketInteraction arg)
{
switch (arg)
{
// Slash Commands
case SocketSlashCommand slashCommand:
await SlashCommands.SearchCommands(slashCommand);
break;
// User Command (context menu)
case SocketUserCommand userCommand:
var user = (SocketGuildUser)userCommand.Data.Member;
await userCommand.RespondAsync(embed: await StatsHandler.UserStatsEmbed(
UserAccounts.GetAccount(user.Id), user.Nickname ?? user.Username,
user.GetAvatarUrl() ?? user.GetDefaultAvatarUrl()),
component: new ComponentBuilder().WithButton("Refresh", $"refresh_user-{userCommand.Data.Member.Id}", style: ButtonStyle.Secondary).Build());
break;
// Button
case SocketMessageComponent buttonCommand:
// /countryall "Refresh" button
if (buttonCommand.Data.CustomId.StartsWith("refresh_country"))
await buttonCommand.ShowCountryForAll();
// /time "Refresh" button
else if (buttonCommand.Data.CustomId.StartsWith("refresh_user"))
await buttonCommand.RefreshUserTime();
// /servertime "Refresh" button
else if (buttonCommand.Data.CustomId == "refresh_server")
await buttonCommand.RefreshServerTime();
// /servertime "Edit Time" button
else if (buttonCommand.Data.CustomId == "editservertime" ||
buttonCommand.Data.CustomId.StartsWith("server"))
await buttonCommand.EditServerTime();
// /set-user-time timezone selection
else if (buttonCommand.Data.CustomId.StartsWith("other"))
await buttonCommand.SetTimeForSomeoneElse();
// /timezone timezone selection
else if (buttonCommand.Data.CustomId.StartsWith("addtimezone"))
await buttonCommand.AddTimeZone();
// /timezone "Refresh" button
else if (buttonCommand.Data.CustomId.StartsWith("refresh_timezone"))
await buttonCommand.UpdateTimezones();
// /timezone "Add Timezone" button
else if (buttonCommand.Data.CustomId.StartsWith("addanothertimezone"))
await buttonCommand.AddTimeZone();
// /timezone "Edit Timezones" button
else if (buttonCommand.Data.CustomId.StartsWith("edittimezones"))
await buttonCommand.ShowEditMenuForTimeZonesCommand();
// roletime and the refresh button
else if (buttonCommand.Data.CustomId.StartsWith("refresh_tworole") ||
buttonCommand.Data.CustomId.StartsWith("refresh_role"))
await buttonCommand.ShowRoleTime();
else if (buttonCommand.Data.CustomId.StartsWith("refresh_twomembersrole") ||
buttonCommand.Data.CustomId.StartsWith("refresh_membersrole"))
await buttonCommand.ShowRoleMembers();
// /timesetup timezone selection
else
await buttonCommand.TimeSetupForSelf();
break;
}
}
private static Task Log(LogMessage arg)
{
Console.WriteLine(arg);
return Task.CompletedTask;
}
private static async Task HandleCommandAsync(SocketMessage s)
{
if (!(s is SocketUserMessage msg) || msg.Author.IsBot) return;
var context = new SocketCommandContext(_socketClient, msg);
if (msg.Content.ToLower().StartsWith("!time") || msg.Content.Contains("<@529569000028373002>"))
{
await context.Channel.SendMessageAsync(embed: new EmbedBuilder()
.WithDescription($"Per Discord requirements, this bot is now 100% interaction based (slash commands, buttons, etc.). Do `/timehelp` for more help. If this bot does not have slash commands enabled on this server, please ask an administrator to re-invite the bot using this link:\n\nhttps://discord.com/api/oauth2/authorize?client_id=529569000028373002&permissions=2048&scope=bot%20applications.commands\n\nSupport Server: {Utilities.SupportServer}")
.Build());
}
}
}
}