Skip to content

Commit

Permalink
Upgrade DSharpPlus to 5.0.0-nightly-02298
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Jun 27, 2024
1 parent bfec989 commit c69eec2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 43 deletions.
8 changes: 4 additions & 4 deletions src/Lykos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

<ItemGroup>
<PackageReference Include="Abyssal.HumanDateParser" Version="2.0.0-20191113.1" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01633" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01633" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-01633" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02298" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-02298" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-02298" />
<PackageReference Include="ini" Version="1.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Minio" Version="4.0.7" />
Expand Down
14 changes: 7 additions & 7 deletions src/Modules/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Mod : BaseCommandModule
{
[Command("delete")]
[Description("Owner only, delete a message.")]
[RequireOwner, RequireBotPermissions(Permissions.ManageMessages)]
[RequireOwner, RequireBotPermissions(DiscordPermissions.ManageMessages)]
public async Task Delete(CommandContext ctx, [Description("ID of the message to delete")] ulong messageId)
{
await ctx.Message.DeleteAsync();
Expand All @@ -14,7 +14,7 @@ public async Task Delete(CommandContext ctx, [Description("ID of the message to

[Command("yeet")]
[Description("Deletes the embed on a given message.")]
[RequirePermissions(DSharpPlus.Permissions.ManageMessages)]
[RequirePermissions(DiscordPermissions.ManageMessages)]
public async Task Yeet(CommandContext ctx, [Description("ID of the message to delete an embed on")] ulong messageId)
{
await ctx.Message.DeleteAsync();
Expand All @@ -24,13 +24,13 @@ public async Task Yeet(CommandContext ctx, [Description("ID of the message to de

[Command("ban")]
[Description("Ban a user. If you can. Do it, I dare you.")]
[RequirePermissions(Permissions.BanMembers)]
[RequirePermissions(DiscordPermissions.BanMembers)]
public async Task Ban(CommandContext ctx, [Description("The user to ban. Must be below both you and the bot in role hierachy.")] DiscordUser target, [Description("The reason for banning the user.\n")] string reason = "No reason provided.")
{

if (ctx.Guild.GetMemberAsync(target.Id) == null)
{
await ctx.Guild.BanMemberAsync(target.Id, 0, $"[Ban by {ctx.User.Username}#{ctx.User.Discriminator}] ${reason}");
await ctx.Guild.BanMemberAsync(target, TimeSpan.Zero, $"[Ban by {ctx.User.Username}#{ctx.User.Discriminator}] ${reason}");
await ctx.Channel.SendMessageAsync($"🔨 Succesfully bent **{target.Username}#{target.Discriminator} (`{target.Id}`)**");
return;
}
Expand All @@ -41,7 +41,7 @@ public async Task Yeet(CommandContext ctx, [Description("ID of the message to de
{
if (AllowedToMod(await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id), member))
{
await member.BanAsync(0, $"[Ban by {ctx.User.Username}#{ctx.User.Discriminator}] {reason}");
await member.BanAsync(TimeSpan.Zero, $"[Ban by {ctx.User.Username}#{ctx.User.Discriminator}] {reason}");
await ctx.Channel.SendMessageAsync($"🔨 Succesfully bent **{target.Username}#{target.Discriminator} (`{target.Id}`)**");
return;
}
Expand All @@ -62,7 +62,7 @@ public async Task Yeet(CommandContext ctx, [Description("ID of the message to de

[Command("unban")]
[Description("Unban a user. If you can. Do it, I dare you.")]
[RequirePermissions(Permissions.BanMembers)]
[RequirePermissions(DiscordPermissions.BanMembers)]
public async Task Unban(CommandContext ctx, DiscordUser target, string reason = "No reason provided.")
{
await target.UnbanAsync(ctx.Guild, $"[Unban by {ctx.User.Username}#{ctx.User.Discriminator}] {reason}");
Expand All @@ -71,7 +71,7 @@ public async Task Unban(CommandContext ctx, DiscordUser target, string reason =

[Command("kick")]
[Description("Kick a user. If you can. Do it, I dare you.")]
[RequirePermissions(Permissions.KickMembers)]
[RequirePermissions(DiscordPermissions.KickMembers)]
public async Task Kick(CommandContext ctx, DiscordMember target, string reason = "No reason provided.")
{
DiscordMember member = await ctx.Guild.GetMemberAsync(target.Id);
Expand Down
10 changes: 5 additions & 5 deletions src/Modules/SlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class BaseContextExtensions
{
public static async Task PrepareResponseAsync(this BaseContext ctx)
{
await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);
await ctx.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource);
}

public static async Task RespondAsync(this BaseContext ctx, string text = null, DiscordEmbed embed = null, bool ephemeral = false, params DiscordComponent[] components)
Expand All @@ -19,7 +19,7 @@ public static async Task RespondAsync(this BaseContext ctx, string text = null,

response.AsEphemeral(ephemeral);

await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, response);
await ctx.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource, response);
}

public static async Task EditAsync(this BaseContext ctx, string text = null, DiscordEmbed embed = null, params DiscordComponent[] components)
Expand Down Expand Up @@ -124,7 +124,7 @@ public async Task AvatarSlashCommand(InteractionContext ctx,
await ctx.RespondAsync(null, embed);
}

[ContextMenu(ApplicationCommandType.UserContextMenu, "Show Avatar")]
[ContextMenu(DiscordApplicationCommandType.UserContextMenu, "Show Avatar")]
public async Task ContextAvatar(ContextMenuContext ctx)
{
string avatarUrl = "";
Expand Down Expand Up @@ -155,13 +155,13 @@ public async Task ContextAvatar(ContextMenuContext ctx)
await ctx.RespondAsync(null, embed, ephemeral: true);
}

[ContextMenu(ApplicationCommandType.UserContextMenu, "lk hug")]
[ContextMenu(DiscordApplicationCommandType.UserContextMenu, "lk hug")]
public async Task ContextHug(ContextMenuContext ctx)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.BlobHug} {ctx.TargetUser.Mention} was given a tight hug by {ctx.User.Mention}!");
}

[ContextMenu(ApplicationCommandType.UserContextMenu, "lk pat")]
[ContextMenu(DiscordApplicationCommandType.UserContextMenu, "lk pat")]
public async Task ContextPat(ContextMenuContext ctx)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.BlobPats} {ctx.TargetUser.Mention} was given a big headpat by {ctx.User.Mention}!");
Expand Down
8 changes: 4 additions & 4 deletions src/Modules/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ await ctx.RespondAsync(new DiscordMessageBuilder().WithContent($"Okay I changed
}

[Command("add")]
[RequireUserPermissions(DSharpPlus.Permissions.ManageRoles)]
[RequireUserPermissions(DiscordPermissions.ManageRoles)]
public async Task ColourmeAdd(CommandContext ctx, DiscordRole role)
{
var configuredRoleIDs = Program.db.ListRange($"colourRoles-{ctx.Guild.Id}", 0, -1);
Expand All @@ -250,7 +250,7 @@ await ctx.RespondAsync(new DiscordMessageBuilder().WithContent($"Okay, I added {
}

[Command("remove")]
[RequireUserPermissions(DSharpPlus.Permissions.ManageRoles)]
[RequireUserPermissions(DiscordPermissions.ManageRoles)]
public async Task ColourmeRemove(CommandContext ctx, DiscordRole role)
{
var configuredRoleIDs = Program.db.ListRange($"colourRoles-{ctx.Guild.Id}", 0, -1);
Expand All @@ -268,7 +268,7 @@ public async Task ColourmeRemove(CommandContext ctx, DiscordRole role)
}

[Command("list")]
[RequireUserPermissions(DSharpPlus.Permissions.ManageRoles)]
[RequireUserPermissions(DiscordPermissions.ManageRoles)]
public async Task ColourmeList(CommandContext ctx)
{
var configuredRoleIDs = Program.db.ListRange($"colourRoles-{ctx.Guild.Id}", 0, -1);
Expand Down Expand Up @@ -351,7 +351,7 @@ public static async Task<bool> CheckRemindersAsync()
.AddField("Context", $"[`Jump to context`]({reminderObject.MessageLink})", true);

var msg = new DiscordMessageBuilder()
.WithEmbed(embed)
.AddEmbed(embed)
.WithContent($"<@!{reminderObject.UserID}>, you asked to be reminded of something:");

if (DmFallback)
Expand Down
42 changes: 19 additions & 23 deletions src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
using OpenAI_API;
using OpenAI_API.Chat;
using OpenAI_API.Models;
Expand Down Expand Up @@ -60,7 +61,7 @@ await UserOrMemberAvatarURL(message.Author, message.Channel.Guild, "png", 128)
}
else
{
prevMsg = (await message.Channel.GetMessagesBeforeAsync(message.Id, 1))[0];
prevMsg = message.Channel.GetMessagesBeforeAsync(message.Id, 1).ToBlockingEnumerable().First();
embed.WithTitle($"Likely replying to {await DisplayName(prevMsg.Author)}")
.WithUrl($"https://discord.com/channels/{message.Channel.Guild.Id}/{message.Channel.Id}/{prevMsg.Id}");
}
Expand Down Expand Up @@ -127,27 +128,22 @@ static async Task MainAsync()
.WithRegion(cfgjson.S3.Region).WithSSL()
.WithHttpClient(new HttpClient());

discord = new DiscordClient(new DiscordConfiguration
DiscordClientBuilder discordBuilder = DiscordClientBuilder.CreateDefault(cfgjson.Token, DiscordIntents.All);

discordBuilder.ConfigureGatewayClient(clientConfig =>
{
Token = cfgjson.Token,
TokenType = TokenType.Bot,
#if DEBUG
MinimumLogLevel = LogLevel.Debug,
#else
MinimumLogLevel = LogLevel.Debug,
#endif
LogUnknownEvents = false,

Intents = DiscordIntents.All,
clientConfig.LogUnknownEvents = false;
clientConfig.LogUnknownAuditlogs = false;
});

Task OnReady(DiscordClient client, SessionReadyEventArgs e)
discord = discordBuilder.Build();

Task OnReady(DiscordClient client, SessionCreatedEventArgs e)
{
Console.WriteLine($"Logged in as {client.CurrentUser.Username}#{client.CurrentUser.Discriminator}");
return Task.CompletedTask;
};


commands = discord.UseCommandsNext(new CommandsNextConfiguration
{
StringPrefixes = cfgjson.Prefixes,
Expand All @@ -167,7 +163,7 @@ Task OnReady(DiscordClient client, SessionReadyEventArgs e)
commands.RegisterCommands(cmdClass);
}

async Task MessageCreated(DiscordClient client, MessageCreateEventArgs e)
async Task MessageCreated(DiscordClient client, MessageCreatedEventArgs e)
{
// gallery
_ = GalleryHandler(e.Message, client);
Expand Down Expand Up @@ -241,7 +237,7 @@ await e.Channel.SendMessageAsync("It looks like you misunderstood my prefix.\n"
}
else if (response.Length > 2000)
{
msg = new DiscordMessageBuilder().WithEmbed(new DiscordEmbedBuilder().WithDescription(response).Build());
msg = new DiscordMessageBuilder().AddEmbed(new DiscordEmbedBuilder().WithDescription(response).Build());
} else
{
msg = new DiscordMessageBuilder().WithContent(response);
Expand All @@ -260,7 +256,7 @@ await e.Channel.SendMessageAsync("It looks like you misunderstood my prefix.\n"
};

// Gallery edit handling
async Task MessageUpdated(DiscordClient client, MessageUpdateEventArgs e)
async Task MessageUpdated(DiscordClient client, MessageUpdatedEventArgs e)
{
// #gallery
GalleryHandler(e.Message, client);

Check warning on line 262 in src/Program.cs

View workflow job for this annotation

GitHub Actions / build-standalone (ubuntu-22.04)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 262 in src/Program.cs

View workflow job for this annotation

GitHub Actions / build-standalone (windows-2022)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
Expand Down Expand Up @@ -308,38 +304,38 @@ async Task CommandsNextService_CommandErrored(CommandsNextExtension cnext, Comma
}
}

Task Discord_ThreadCreated(DiscordClient client, ThreadCreateEventArgs e)
Task Discord_ThreadCreated(DiscordClient client, ThreadCreatedEventArgs e)
{
client.Logger.LogDebug(eventId: EventID, $"Thread created in {e.Guild.Name}. Thread Name: {e.Thread.Name}");
return Task.CompletedTask;
}

Task Discord_ThreadUpdated(DiscordClient client, ThreadUpdateEventArgs e)
Task Discord_ThreadUpdated(DiscordClient client, ThreadUpdatedEventArgs e)
{
client.Logger.LogDebug(eventId: EventID, $"Thread updated in {e.Guild.Name}. New Thread Name: {e.ThreadAfter.Name}");
return Task.CompletedTask;
}

Task Discord_ThreadDeleted(DiscordClient client, ThreadDeleteEventArgs e)
Task Discord_ThreadDeleted(DiscordClient client, ThreadDeletedEventArgs e)
{
client.Logger.LogDebug(eventId: EventID, $"Thread deleted in {e.Guild.Name}. Thread Name: {e.Thread.Name ?? "Unknown"}");
return Task.CompletedTask;
}

Task Discord_ThreadListSynced(DiscordClient client, ThreadListSyncEventArgs e)
Task Discord_ThreadListSynced(DiscordClient client, ThreadListSyncedEventArgs e)
{
client.Logger.LogDebug(eventId: EventID, $"Threads synced in {e.Guild.Name}.");
return Task.CompletedTask;
}

Task Discord_ThreadMemberUpdated(DiscordClient client, ThreadMemberUpdateEventArgs e)
Task Discord_ThreadMemberUpdated(DiscordClient client, ThreadMemberUpdatedEventArgs e)
{
client.Logger.LogDebug(eventId: EventID, $"Thread member updated.");
Console.WriteLine($"Discord_ThreadMemberUpdated fired for thread {e.ThreadMember.ThreadId}. User ID {e.ThreadMember.Id}.");
return Task.CompletedTask;
}

Task Discord_ThreadMembersUpdated(DiscordClient client, ThreadMembersUpdateEventArgs e)
Task Discord_ThreadMembersUpdated(DiscordClient client, ThreadMembersUpdatedEventArgs e)
{
client.Logger.LogDebug(eventId: EventID, $"Thread members updated in {e.Guild.Name}.");
return Task.CompletedTask;
Expand Down

0 comments on commit c69eec2

Please sign in to comment.