Skip to content

Commit 987525e

Browse files
Added Help Command / Bug Fixes
1 parent c62fd22 commit 987525e

File tree

9 files changed

+75
-38
lines changed

9 files changed

+75
-38
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ obj/
33
/packages/
44
riderModule.iml
55
/_ReSharper.Caches/
6-
.idea/
6+
.idea/
7+
Portal.Bot.sln.DotSettings.user

BotService.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ public async Task StartAsync(CancellationToken cancellationToken)
2626

2727
discordSocketClient.Ready += async () =>
2828
{
29-
// Setting up slash commands and context commands
30-
ulong guildId = Convert.ToUInt64(configuration["Bot:GuildId"]);
31-
var guild = discordSocketClient.GetGuild(guildId);
32-
await guild.BulkOverwriteApplicationCommandAsync(new ApplicationCommandProperties[]
29+
_ = Task.Run(async () =>
3330
{
34-
AddContextCommand().Build()
35-
});
36-
await interactionService.RegisterCommandsToGuildAsync(guildId);
31+
// Setting up slash commands and context commands
32+
ulong guildId = Convert.ToUInt64(configuration["Bot:GuildId"]);
33+
var guild = discordSocketClient.GetGuild(guildId);
34+
await guild.BulkOverwriteApplicationCommandAsync(new ApplicationCommandProperties[]
35+
{
36+
AddContextCommand().Build()
37+
});
38+
await interactionService.RegisterCommandsToGuildAsync(guildId);
39+
}, cancellationToken);
40+
await Task.CompletedTask;
3741
};
3842

3943
// Starting discord socket client

CommandHandlers/PortalCommandHandler.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,11 @@ await Context.Channel.SendMessageAsync(
3333
{
3434
var referenceMessage = Context.Message.ReferencedMessage;
3535
await(rxChannel as ISocketMessageChannel)!.SendMessageAsync(
36-
embed: new RxPortalEmbed((Context.Channel as SocketGuildChannel)!,
36+
embed: new RxPortalEmbed(Context.Channel,
3737
Context.Guild, referenceMessage as SocketMessage).Build());
3838
}
3939

4040
await Context.Channel.SendMessageAsync(embed: new TxPortalEmbed(rxChannel, Context.Guild).Build());
4141
await helper.LogToLogChannelAsync(Context.Guild, Context.Channel.Id, rxChannel.Id);
4242
}
43-
44-
[Command("teleport")]
45-
[Alias("portal", "tp")]
46-
[Summary("Opens a portal from current rxChannel to provided rxChannel")]
47-
public async Task HandleTeleportWoArgs()
48-
49-
{
50-
var message = Context.Message.ReferencedMessage;
51-
await ReplyAsync(message.ToString());
52-
}
5343
}

Embeds/HelpEmbed.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Discord;
2+
using Portal.Common;
3+
// ReSharper disable All
4+
5+
namespace Portal.Embeds;
6+
7+
public class HelpEmbed : IEmbedProvider
8+
{
9+
public Embed Build()
10+
{
11+
const string description = """
12+
Made with ❤️ by [CosmicPredator](https://github.com/CosmicPredator)
13+
## Commands Reference
14+
15+
`/teleport {channel}`
16+
Opens a portal from current channel to provided rxChannel.
17+
Alias: `!tp`, `!teleport`, `!portal`
18+
19+
`/exclude`
20+
Exclude a channel for being read only.
21+
22+
`/logchannel {channel}`
23+
Sets the channel where the bot logs information.
24+
25+
""";
26+
var embed = new EmbedBuilder()
27+
.WithAuthor("Portal bot v1.0")
28+
.WithDescription(description)
29+
.WithColor(Color.Green)
30+
.WithFooter("# Glory to CPP");
31+
return embed.Build();
32+
}
33+
}

Embeds/PortalEmbeds.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class TxPortalEmbed(SocketGuildChannel channel, SocketGuild guild) : IEmb
1515
.Build();
1616
}
1717

18-
public class RxPortalEmbed(SocketGuildChannel channel, SocketGuild guild, SocketMessage? annotatedMessage = null) : IEmbedProvider
18+
public class RxPortalEmbed(ISocketMessageChannel channel, SocketGuild guild, IMessage? annotatedMessage = null) : IEmbedProvider
1919
{
2020
public Embed Build()
2121
{
@@ -25,10 +25,13 @@ public Embed Build()
2525
$"A Portal has been opened from <#{channel.Id}>!\n[Teleport back](https://discord.com/channels/{guild.Id}/{channel.Id})")
2626
.WithThumbnailUrl("https://i.gifer.com/origin/c7/c795fccbcc24322a9107cca44252227b_w200.gif")
2727
.WithColor(0x9392BA);
28-
if (annotatedMessage != null || !string.IsNullOrEmpty(annotatedMessage!.Content))
28+
if (annotatedMessage == null) return embed.Build();
29+
if (!string.IsNullOrEmpty(annotatedMessage!.Content))
2930
{
31+
string truncatedMessage = annotatedMessage.Content.Length > 20
32+
? $"{annotatedMessage.Content[..20]}..." : annotatedMessage.Content;
3033
embed.AddField("Annotated Message",
31-
$"{annotatedMessage.Content} [Go to Message](https://discord.com/channels/{guild.Id}/{channel.Id}/{annotatedMessage.Id})");
34+
$"{truncatedMessage} [Go to Message](https://discord.com/channels/{guild.Id}/{channel.Id}/{annotatedMessage.Id})");
3235
}
3336
return embed.Build();
3437
}

InteractionHandlers/PingHandler.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ public async Task HandlePingAsync()
1313
{
1414
await RespondAsync(embed: new PongEmbed(Context.Client.Latency).Build(), ephemeral: true);
1515
}
16+
17+
[SlashCommand("help", "Displays help message")]
18+
public async Task HandleHelpAsync()
19+
{
20+
await RespondAsync(embed: new HelpEmbed().Build(), ephemeral: true);
21+
}
1622
}

InteractionHandlers/TeleportContextMenuHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public async Task HandleContextTeleport(string messageId, string[] channelIds)
4242
if (!helper.IsChannelExcluded(rxChannel, Context.Guild, dbContext))
4343
{
4444
await (rxChannel as ISocketMessageChannel)!.SendMessageAsync(
45-
embed: new RxPortalEmbed((Context.Channel as SocketGuildChannel)!, Context.Guild, message as SocketMessage).Build());
45+
embed: new RxPortalEmbed(Context.Channel, Context.Guild, message).Build());
4646
}
4747
await RespondAsync(embed: new TxPortalEmbed(rxChannel, Context.Guild).Build());
4848
await helper.LogToLogChannelAsync(Context.Guild, Context.Channel.Id, rxChannel.Id);

InteractionHandlers/TeleportHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class TeleportHandler(BotDbContext dbContext, Helper helper) : Interactio
1212
{
1313
// /teleport - this command does the main teleportation things and opening
1414
// and closing of portals
15-
[SlashCommand("teleport", "Opens a portal from current rxChannel to provided rxChannel")]
15+
[SlashCommand("teleport", "Opens a portal from current channel to provided rxChannel")]
1616
public async Task HandleTeleport([Name("channel")]SocketGuildChannel rxChannel)
1717
{
1818
if (rxChannel.Id == Context.Channel.Id)
@@ -30,7 +30,7 @@ public async Task HandleTeleport([Name("channel")]SocketGuildChannel rxChannel)
3030
if (!helper.IsChannelExcluded(rxChannel, Context.Guild, dbContext))
3131
{
3232
await(rxChannel as ISocketMessageChannel)!.SendMessageAsync(
33-
embed: new RxPortalEmbed((Context.Channel as SocketGuildChannel)!, Context.Guild).Build());
33+
embed: new RxPortalEmbed(Context.Channel, Context.Guild).Build());
3434
}
3535

3636
await RespondAsync(embed: new TxPortalEmbed(rxChannel, Context.Guild).Build());

LICENSE.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2-
Version 2, December 2004
3-
4-
Copyright (C) 2024 Cosmic Predator <https://github.com/CosmicPredator>
5-
6-
Everyone is permitted to copy and distribute verbatim or modified
7-
copies of this license document, and changing it is allowed as long
8-
as the name is changed.
9-
10-
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11-
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12-
13-
0. You just DO WHAT THE FUCK YOU WANT TO.
1+
 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2+
Version 2, December 2004
3+
4+
Copyright (C) 2004 Sam Hocevar <[email protected]>
5+
6+
Everyone is permitted to copy and distribute verbatim or modified
7+
copies of this license document, and changing it is allowed as long
8+
as the name is changed.
9+
10+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12+
13+
0. You just DO WHAT THE FUCK YOU WANT TO.

0 commit comments

Comments
 (0)