Skip to content

Commit

Permalink
Upgrade DSharpPlus to 5.0.0-nightly-01851, adapt code to fit new IAsy…
Browse files Browse the repository at this point in the history
…ncEnumerable
  • Loading branch information
Erisa committed Oct 26, 2023
1 parent 6e755d3 commit d187eb3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
1 change: 0 additions & 1 deletion Checks/ListChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public static (bool success, string? flaggedWord) CheckForNaughtyWords(string in

for (int i = 0; i < arrayOfWords.Length; i++)
{
string naughtyWord = "";
bool isNaughty = false;
foreach (string naughty in naughtyWords)
{
Expand Down
7 changes: 4 additions & 3 deletions Cliptok.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

<ItemGroup>
<PackageReference Include="Abyssal.HumanDateParser" Version="2.0.0-20191113.1" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01694" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01694" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-01694" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-01851" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-01851" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-01851" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.Expressions" Version="3.4.1" />
Expand All @@ -20,6 +20,7 @@
<PackageReference Include="Serilog.Sinks.TextWriter" Version="2.1.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Commands/Dehoist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ await discordMember.ModifyAsync(a =>
public async Task MassDehoist(CommandContext ctx)
{
var msg = await ctx.RespondAsync($"{Program.cfgjson.Emoji.Loading} Working on it. This will take a while.");
var discordMembers = await ctx.Guild.GetAllMembersAsync();
var discordMembers = await ctx.Guild.GetAllMembersAsync().ToListAsync();
int failedCount = 0;

foreach (DiscordMember discordMember in discordMembers)
Expand All @@ -82,7 +82,7 @@ public async Task MassDehoist(CommandContext ctx)
}

_ = msg.DeleteAsync();
await ctx.Channel.SendMessageAsync(new DiscordMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Success} Successfully dehoisted {discordMembers.Count - failedCount} of {discordMembers.Count} member(s)! (Check Audit Log for details)").WithReply(ctx.Message.Id, true, false));
await ctx.Channel.SendMessageAsync(new DiscordMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Success} Successfully dehoisted {discordMembers.Count() - failedCount} of {discordMembers.Count()} member(s)! (Check Audit Log for details)").WithReply(ctx.Message.Id, true, false));
}

[Command("massundehoist")]
Expand Down
8 changes: 4 additions & 4 deletions Commands/InteractionCommands/ClearInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task ClearSlashCommand(InteractionContext ctx,
List<DiscordMessage> messagesToClear = new();
if (upTo == "")
{
var messages = await ctx.Channel.GetMessagesAsync((int)count);
var messages = await ctx.Channel.GetMessagesAsync((int)count).ToListAsync();
messagesToClear = messages.ToList();
}
else
Expand Down Expand Up @@ -90,15 +90,15 @@ public async Task ClearSlashCommand(InteractionContext ctx,
message = await ctx.Channel.GetMessageAsync(messageId);

// List of messages to delete, up to (not including) the one we just got.
var firstMsg = (await ctx.Channel.GetMessagesAfterAsync(message.Id, 1))[0];
var firstMsg = (await ctx.Channel.GetMessagesAfterAsync(message.Id, 1).ToListAsync())[0];
var firstMsgId = firstMsg.Id;
messagesToClear.Add(firstMsg);
while (true)
{
var newMessages = (await ctx.Channel.GetMessagesAfterAsync(firstMsgId, 100)).ToList();
var newMessages = (await ctx.Channel.GetMessagesAfterAsync(firstMsgId, 100).ToListAsync()).ToList();
messagesToClear.AddRange(newMessages);
firstMsgId = newMessages.First().Id;
if (newMessages.Count < 100)
if (newMessages.Count() < 100)
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Events/DirectMessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public static async void DirectMessageEventHandler(DiscordMessage message)
bool sentAutoresponse = false;

// Make sure there is a message before the current one, otherwise an exception could be thrown
var msgsBefore = await message.Channel.GetMessagesBeforeAsync(message.Id, 1);
if (msgsBefore.Count > 0)
var msgsBefore = await message.Channel.GetMessagesBeforeAsync(message.Id, 1).ToListAsync();
if (msgsBefore.Count() > 0)
{
// Get single message before the current one
var msgBefore = msgsBefore[0];
Expand Down
6 changes: 3 additions & 3 deletions Events/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static async Task MessageDeleted(DiscordClient client, MessageDeleteEvent
IReadOnlyList<DiscordMessage> messages;
try
{
messages = await e.Channel.GetMessagesAsync(1);
messages = await e.Channel.GetMessagesAsync(1).ToListAsync();
}
catch (DSharpPlus.Exceptions.NotFoundException ex)
{
Expand Down Expand Up @@ -437,7 +437,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, DiscordMessag
.WithTimestamp(DateTime.Now)
.WithAuthor(DiscordHelpers.UniqueUsername(message.Author), null, $"https://cdn.discordapp.com/avatars/{message.Author.Id}/{message.Author.AvatarHash}.png?size=128");

var lastMsgs = await message.Channel.GetMessagesBeforeAsync(message.Id, 50);
var lastMsgs = await message.Channel.GetMessagesBeforeAsync(message.Id, 50).ToListAsync();
var msgMatch = lastMsgs.FirstOrDefault(m => m.Author.Id == message.Author.Id);

if (msgMatch is not null)
Expand Down Expand Up @@ -586,7 +586,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, DiscordMessag
Program.db.SetAdd("processedFeedbackHubThreads", thread.Id);

// we need to make sure this is the first message in the channel
if ((await thread.GetMessagesBeforeAsync(message.Id)).Count == 0)
if ((await thread.GetMessagesBeforeAsync(message.Id).ToListAsync()).Count == 0)
{
// lock thread if there is no possible feedback hub link
if (!message.Content.Contains("aka.ms/") && !message.Content.Contains("feedback-hub:"))
Expand Down
6 changes: 3 additions & 3 deletions Events/VoiceEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static async Task VoiceStateUpdate(DiscordClient client, VoiceStateUpdate
List<DiscordMessage> messages = new();
try
{
var firstMsg = (await e.Before.Channel.GetMessagesAsync(1)).FirstOrDefault();
var firstMsg = (await e.Before.Channel.GetMessagesAsync(1).ToListAsync()).FirstOrDefault();
if (firstMsg == default)
return;

Expand All @@ -68,9 +68,9 @@ public static async Task VoiceStateUpdate(DiscordClient client, VoiceStateUpdate
// delete all the messages from the channel
while (true)
{
var newmsgs = (await e.Before.Channel.GetMessagesBeforeAsync(lastMsgId, 100)).ToList();
var newmsgs = await e.Before.Channel.GetMessagesBeforeAsync(lastMsgId, 100).ToListAsync();
messages.AddRange(newmsgs);
if (newmsgs.Count < 100)
if (newmsgs.Count() < 100)
break;
else
lastMsgId = newmsgs.Last().Id;
Expand Down

0 comments on commit d187eb3

Please sign in to comment.