Skip to content

Commit

Permalink
Update to Discord.Net 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Voltstro committed Mar 14, 2022
1 parent 1c70a94 commit a213159
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/Pootis-Bot/Core/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public async Task StartBot()

Client = new DiscordSocketClient(new DiscordSocketConfig
{
LogLevel = LogSeverity.Verbose
LogLevel = LogSeverity.Verbose,
GatewayIntents = Config.bot.GatewayIntents
});

Logger.Debug("Setting up events");
Expand Down
10 changes: 9 additions & 1 deletion src/Pootis-Bot/Entities/ConfigFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Discord;
using Newtonsoft.Json;
using Pootis_Bot.Attributes;
using Pootis_Bot.Structs.Config;

Expand Down Expand Up @@ -88,5 +89,12 @@ public class ConfigFile
/// Setting related to voting
/// </summary>
public VoteSettings VoteSettings;

/// <summary>
/// Gateway intents
/// </summary>
public GatewayIntents GatewayIntents { get; set; } = GatewayIntents.AllUnprivileged |
GatewayIntents.GuildMembers |
GatewayIntents.GuildPresences;
}
}
14 changes: 7 additions & 7 deletions src/Pootis-Bot/Events/MessageEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ namespace Pootis_Bot.Events
/// </summary>
public class MessageEvents
{
public async Task MessageDeleted(Cacheable<IMessage, ulong> cache, ISocketMessageChannel channel)
public async Task MessageDeleted(Cacheable<IMessage, ulong> messageCache, Cacheable<IMessageChannel, ulong> channel)
{
try
{
SocketGuild guild = ((SocketGuildChannel) channel).Guild;
SocketGuild guild = ((SocketGuildChannel) channel.Value).Guild;
ServerList server = ServerListsManager.GetServer(guild);
if (cache.Id == server.RuleMessageId)
if (messageCache.Id == server.RuleMessageId)
{
//The rule reaction will be disabled and the owner of the guild will be notified.
server.RuleEnabled = false;

ServerListsManager.SaveServerList();

IDMChannel dm = await guild.Owner.GetOrCreateDMChannelAsync();
IDMChannel dm = await guild.Owner.CreateDMChannelAsync();
await dm.SendMessageAsync(
$"Your rule reaction on the Discord server **{guild.Name}** has been disabled due to the message being deleted.\n" +
"You can enable it again after setting a new reaction message with the command `setuprulesmessage` and then enabling the feature again with `togglerulereaction`.");
Expand All @@ -40,11 +40,11 @@ await dm.SendMessageAsync(
}

public async Task MessageBulkDeleted(IReadOnlyCollection<Cacheable<IMessage, ulong>> cacheable,
ISocketMessageChannel channel)
Cacheable<IMessageChannel, ulong> channel)
{
try
{
SocketGuild guild = ((SocketGuildChannel) channel).Guild;
SocketGuild guild = ((SocketGuildChannel) channel.Value).Guild;
ServerList server = ServerListsManager.GetServer(guild);

//Depending on how many message were deleted, this could take awhile. Or well I assume that, it would need to be tested
Expand All @@ -57,7 +57,7 @@ public async Task MessageBulkDeleted(IReadOnlyCollection<Cacheable<IMessage, ulo

ServerListsManager.SaveServerList();

IDMChannel dm = await guild.Owner.GetOrCreateDMChannelAsync();
IDMChannel dm = await guild.Owner.CreateDMChannelAsync();
await dm.SendMessageAsync(
$"Your rule reaction on the Discord server **{guild.Name}** has been disabled due to the message being deleted.\n" +
"You can enable it again after setting setting a new reaction message with the command `setuprulesmessage` and then enabling the feature again with `togglerulereaction`.");
Expand Down
4 changes: 2 additions & 2 deletions src/Pootis-Bot/Events/ReactionEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Pootis_Bot.Events
/// </summary>
public class ReactionEvents
{
public Task ReactionAdded(Cacheable<IUserMessage, ulong> cache, ISocketMessageChannel channel,
public Task ReactionAdded(Cacheable<IUserMessage, ulong> cache, Cacheable<IMessageChannel, ulong> channel,
SocketReaction reaction)
{
try
Expand All @@ -35,7 +35,7 @@ public Task ReactionAdded(Cacheable<IUserMessage, ulong> cache, ISocketMessageCh
if (reaction.MessageId == 0)
return Task.CompletedTask;

SocketGuild guild = ((SocketGuildChannel) channel).Guild;
SocketGuild guild = ((SocketGuildChannel) channel.Value).Guild;
ServerList server = ServerListsManager.GetServer(guild);

//If the message the user reacted to is the rules message
Expand Down
4 changes: 2 additions & 2 deletions src/Pootis-Bot/Events/RoleEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task RoleDeleted(SocketRole role)
ServerList server = ServerListsManager.GetServer(guild);

//Setup the dm channel even though we might not even use it just makes it so I don't have to repeat this a whole bunch of times.
IDMChannel dm = await guild.Owner.GetOrCreateDMChannelAsync();
IDMChannel dm = await guild.Owner.CreateDMChannelAsync();

//The rule role was deleted
if (role.Id == server.RuleRoleId)
Expand Down Expand Up @@ -83,7 +83,7 @@ public async Task RoleUpdated(SocketRole before, SocketRole after)
SocketGuild guild = before.Guild;
ServerList server = ServerListsManager.GetServer(guild);

IDMChannel dm = await guild.Owner.GetOrCreateDMChannelAsync();
IDMChannel dm = await guild.Owner.CreateDMChannelAsync();

//Check all server role pings to make sure they are still mentionable
List<ServerRoleToRoleMention> rolesToRemove = server.RoleToRoleMentions
Expand Down
4 changes: 2 additions & 2 deletions src/Pootis-Bot/Events/UserEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public async Task UserJoined(SocketGuildUser user)
}
}

public async Task UserLeft(SocketGuildUser user)
public async Task UserLeft(SocketGuild guild, SocketUser user)
{
try
{
if (!user.IsBot)
{
ServerList server = ServerListsManager.GetServer(user.Guild);
ServerList server = ServerListsManager.GetServer(guild);
if (server.GoodbyeMessageEnabled)
{
//Format the message
Expand Down
2 changes: 1 addition & 1 deletion src/Pootis-Bot/Modules/Account/AccountDataManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ await Context.Channel.SendMessageAsync(
File.WriteAllText($"temp/{Context.User.Id}.json", json);

//Get the user's dm and send the file
IDMChannel dm = await Context.User.GetOrCreateDMChannelAsync();
IDMChannel dm = await Context.User.CreateDMChannelAsync();
await dm.SendFileAsync($"temp/{Context.User.Id}.json", "Here is your user data, all in one JSON file!");

//Delete the file
Expand Down
3 changes: 1 addition & 2 deletions src/Pootis-Bot/Modules/Server/Setup/ServerSetupQuick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ private async Task SetupServerQuick(SocketGuild guild, ISocketMessageChannel cha
else
{
//create a new role called member
memberRole = await guild.CreateRoleAsync("Member", memberRoleGuildPermissions, Color.LightGrey, false,
null);
memberRole = await guild.CreateRoleAsync("Member", memberRoleGuildPermissions, Color.LightGrey);
}

//Modify @everyone role
Expand Down
4 changes: 2 additions & 2 deletions src/Pootis-Bot/Modules/Server/Setup/ServerSetupStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ServerSetupStatus : ModuleBase<SocketCommandContext>
[RequireGuildOwner]
public async Task Setup()
{
IDMChannel dm = await Context.User.GetOrCreateDMChannelAsync();
IDMChannel dm = await Context.User.CreateDMChannelAsync();
ServerList server = ServerListsManager.GetServer(Context.Guild);
EmbedBuilder embed = new EmbedBuilder();

Expand Down Expand Up @@ -115,7 +115,7 @@ public async Task Setup()
[RequireGuildOwner]
public async Task SetupSpam()
{
IDMChannel dm = await Context.User.GetOrCreateDMChannelAsync();
IDMChannel dm = await Context.User.CreateDMChannelAsync();
ServerList server = ServerListsManager.GetServer(Context.Guild);
EmbedBuilder embed = new EmbedBuilder();

Expand Down
4 changes: 2 additions & 2 deletions src/Pootis-Bot/Pootis-Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Discord.Net" Version="2.3.0" />
<PackageReference Include="Discord.Net" Version="3.4.1" />
<PackageReference Include="Google.Apis.Customsearch.v1" Version="1.49.0.2084" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="MP3Sharp" Version="1.0.5" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
Expand Down
4 changes: 2 additions & 2 deletions src/Pootis-Bot/Services/BotCheckServerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static async Task CheckServerWelcomeSettings(ServerList server)
if (client.GetChannel(server.WelcomeChannelId) == null && server.WelcomeMessageEnabled)
{
SocketGuild guild = client.GetGuild(server.GuildId);
IDMChannel ownerDm = await client.GetGuild(server.GuildId).Owner.GetOrCreateDMChannelAsync();
IDMChannel ownerDm = await client.GetGuild(server.GuildId).Owner.CreateDMChannelAsync();

await ownerDm.SendMessageAsync(
$"{guild.Owner.Mention}, your server **{guild.Name}** welcome channel has been disabled due to that it no longer exist since the last bot up time.\n" +
Expand Down Expand Up @@ -175,7 +175,7 @@ public static async Task CheckServerRuleMessageChannel(ServerList server)

ServerListsManager.SaveServerList();

IDMChannel dm = await client.GetGuild(server.GuildId).Owner.GetOrCreateDMChannelAsync();
IDMChannel dm = await client.GetGuild(server.GuildId).Owner.CreateDMChannelAsync();
await dm.SendMessageAsync(
$"Your rule reaction on the Discord server **{client.GetGuild(server.GuildId).Name}** has been disabled due to the message being deleted.\n" +
"You can enable it again after setting a new reaction message with the command `setuprulesmessage` and then enabling the feature again with `togglerulereaction`.");
Expand Down
2 changes: 1 addition & 1 deletion src/Pootis-Bot/Services/ReminderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static async Task RemindAsyncSeconds(SocketUser guild, int time, string m

await Task.Delay(convert);

IDMChannel dm = await guild.GetOrCreateDMChannelAsync();
IDMChannel dm = await guild.CreateDMChannelAsync();

EmbedBuilder embed = new EmbedBuilder();
embed.WithTitle("Reminder");
Expand Down
2 changes: 1 addition & 1 deletion src/Pootis-Bot/Services/Voting/VotingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static async Task EndVote(Vote vote, SocketGuild guild)
userDmEmbed.WithDescription($"Your vote that you started on the **{guild.Name}** guild is now over.\n" +
$"You can see the results [here](https://discordapp.com/channels/{guild.Id}/{vote.VoteMessageChannelId}/{vote.VoteMessageId}).");

IDMChannel userDm = await user.GetOrCreateDMChannelAsync();
IDMChannel userDm = await user.CreateDMChannelAsync();
await userDm.SendMessageAsync("", false, userDmEmbed.Build());
}

Expand Down

0 comments on commit a213159

Please sign in to comment.