Skip to content

Commit 9e0bc7c

Browse files
authored
Merege Develop (#60)
1 parent a3132f9 commit 9e0bc7c

File tree

6 files changed

+101
-5
lines changed

6 files changed

+101
-5
lines changed

Boolean/Config.cs

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public static class Strings
2222
"__**/set channel <purpose>**__\n" +
2323
"\u2800Marks a channel for a specific purpose, such as for welcoming messages, starboard, server logs, etc.\n";
2424

25+
public const string ContributeMsg = "Hello and thank you for your interest in contributing to Boolean!\n\n" +
26+
"To get started, please visit our open source [repository](https://github.com/conaticusgrp/boolean) and check out our [contributing guide](https://github.com/conaticusgrp/boolean/blob/main/CONTRIBUTING.md). " +
27+
"Once completed, you may review our [issues](https://github.com/conaticusgrp/boolean/issues) and choose whichever task you are interested in.";
28+
2529
public static string WelcomeMsg(string userDisplay, string serverName) =>
2630
$"Hello {userDisplay}, thank you for joining the **{serverName}** server!";
2731
}

Boolean/DataContext.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,5 @@ public class StarReaction
9494
public uint ReactionCount { get; set; } = 1;
9595

9696
public ulong MessageSnowflake { get; set; }
97-
98-
9997
}
98+

Boolean/EventHandlers.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ public async Task UserJoined(IGuildUser user)
106106
public async Task ReactionAdded(Cacheable<IUserMessage, ulong> cachedMessage,
107107
Cacheable<IMessageChannel, ulong> originChannel, SocketReaction reaction)
108108
{
109-
if (reaction.Emote.Name != Config.Emojis.Star)
109+
var message = await cachedMessage.GetOrDownloadAsync();
110+
111+
if (reaction.Emote.Name != Config.Emojis.Star || message.Author.IsBot)
110112
return;
111113

112114
// Message IDs are unique across discord yay
@@ -116,7 +118,6 @@ public async Task ReactionAdded(Cacheable<IUserMessage, ulong> cachedMessage,
116118
.FirstOrDefaultAsync(sr => sr.MessageSnowflake == cachedMessage.Id);
117119

118120
if (starReaction != null) {
119-
var message = await cachedMessage.GetOrDownloadAsync();
120121
await HandleExistingStarReaction(db, message, starReaction);
121122
return;
122123
}
@@ -189,7 +190,9 @@ private async Task HandleExistingStarReaction(DataContext db, IUserMessage messa
189190
public async Task ReactionRemoved(Cacheable<IUserMessage, ulong> cachedMessage,
190191
Cacheable<IMessageChannel, ulong> originChannel, SocketReaction reaction)
191192
{
192-
if (reaction.Emote.Name != Config.Emojis.Star)
193+
var message = await cachedMessage.GetOrDownloadAsync();
194+
195+
if (reaction.Emote.Name != Config.Emojis.Star || message.Author.IsBot)
193196
return;
194197

195198
var db = serviceProvider.GetRequiredService<DataContext>();

Boolean/Modules/AdminUtils.cs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Runtime.InteropServices.ObjectiveC;
2+
using Boolean.Util;
3+
using Discord;
4+
using Discord.Interactions;
5+
using Discord.WebSocket;
6+
7+
namespace Boolean;
8+
9+
[DefaultMemberPermissions(GuildPermission.Administrator)]
10+
public class AdminUtils : InteractionModuleBase<SocketInteractionContext>
11+
{
12+
[SlashCommand("repeat", "Repeats the message you send into the channel")]
13+
public async Task Repeat(string msg)
14+
{
15+
await ReplyAsync(msg, allowedMentions: AllowedMentions.None);
16+
17+
// Annoying we have to do this to end the interaction.
18+
await RespondAsync(embed: new EmbedBuilder
19+
{
20+
Description = "Repeated your message",
21+
Color = EmbedColors.Normal
22+
}.Build(), ephemeral: true);
23+
}
24+
25+
[SlashCommand("clear", "Clears a specified number of messages in a channel")]
26+
public async Task Clear(int messageCount)
27+
{
28+
if (messageCount is < 1 or > 500) {
29+
await RespondAsync(embed: new EmbedBuilder
30+
{
31+
Description = "Number of messages to delete must be between 1-500.",
32+
Color = EmbedColors.Fail,
33+
}.Build(), ephemeral: true);
34+
35+
return;
36+
}
37+
38+
if (Context.Channel is not SocketTextChannel textChannel) {
39+
await RespondAsync(embed: new EmbedBuilder
40+
{
41+
Description = "Can only delete messages in a text channel.",
42+
Color = EmbedColors.Fail,
43+
}.Build(), ephemeral: true);
44+
45+
return;
46+
}
47+
48+
var messages = await Context.Channel.GetMessagesAsync(messageCount).FlattenAsync();
49+
await textChannel.DeleteMessagesAsync(messages);
50+
51+
await RespondAsync(embed: new EmbedBuilder
52+
{
53+
Description = $"Deleted `{messages.Count()}` messages.",
54+
Color = EmbedColors.Success,
55+
}.Build());
56+
}
57+
58+
}

Boolean/Modules/BotInfo.cs

+13
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,17 @@ public async Task Help()
4444
};
4545
await RespondAsync(embed: embed.Build(), ephemeral: true);
4646
}
47+
48+
[SlashCommand("contribute", "Information on how to contribute to the discord bot.")]
49+
public async Task Contribute()
50+
{
51+
var embed = new EmbedBuilder
52+
{
53+
Title = "Contributing to Boolean",
54+
Description = Config.Strings.ContributeMsg,
55+
Color = EmbedColors.Normal
56+
};
57+
58+
await RespondAsync(embed: embed.Build(), ephemeral: true);
59+
}
4760
}

Boolean/Modules/FunUtils.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Boolean.Util;
2+
using Discord;
3+
using Discord.Interactions;
4+
5+
namespace Boolean;
6+
7+
public class FunUtils : InteractionModuleBase<SocketInteractionContext>
8+
{
9+
[SlashCommand("execute", "Executes a fiendish individual.")]
10+
public async Task Execute(IUser user, string? reason = null)
11+
{
12+
await RespondAsync(embed: new EmbedBuilder
13+
{
14+
Description = $"{user.Mention} has been executed by {Context.User.Mention}"
15+
+ (reason != null ? $"\nReason: `{reason}`" : ""),
16+
Color = EmbedColors.Normal,
17+
}.Build());
18+
}
19+
}

0 commit comments

Comments
 (0)