Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies and modules #169

Merged
merged 4 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch: {}

jobs:

Expand All @@ -15,9 +16,9 @@ jobs:

- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: 3.1.301
dotnet-version: 8.0.x

- name: Build Windows binary
run: dotnet publish --runtime win-x64 --configuration Release --output artifacts/win-x64 /p:PublishSingleFile=true Floofbot/Floofbot.csproj
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,5 @@ __pycache__/

Floofbot/config.yaml
/Floofbot/floofData.db
/Floofbot/config.yaml
/Floofbot/app.config
4 changes: 2 additions & 2 deletions Discord.Addons.Interactive/Discord.Addons.Interactive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Discord.Net.Commands" Version="2.3.0-dev-20201223.7" />
<PackageReference Include="Discord.Net.WebSocket" Version="2.3.0-dev-20201223.7" />
<PackageReference Include="Discord.Net.Commands" Version="3.13.0" />
<PackageReference Include="Discord.Net.WebSocket" Version="3.13.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Discord.Addons.Interactive/InteractiveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private static async Task HandlerAsync(SocketMessage message, SocketCommandConte
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
private async Task HandleReactionAsync(Cacheable<IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
private async Task HandleReactionAsync(Cacheable<IUserMessage, ulong> message, Cacheable<IMessageChannel, ulong> channel, SocketReaction reaction)
{
if (reaction.UserId == Discord.CurrentUser.Id)
{
Expand Down
26 changes: 10 additions & 16 deletions Floofbot/Floofbot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>netcoreapp8.0</TargetFramework>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iShauny i opened #174. ptal.

</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -12,24 +12,18 @@
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<ProjectReference Include="../Discord.Addons.Interactive/Discord.Addons.Interactive.csproj" />
<PackageReference Include="Discord.Net" Version="2.3.0-dev-20201223.7" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.3">
<PackageReference Include="Discord.Net" Version="3.13.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="UnitsNet" Version="4.129.0" />
<PackageReference Include="YamlDotNet" Version="8.1.2" />
</ItemGroup>

<ItemGroup>
<None Update="config.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="UnitsNet" Version="5.38.2" />
<PackageReference Include="YamlDotNet" Version="13.7.1" />
</ItemGroup>

<Target Name="CopyConfigs" AfterTargets="AfterBuild">
Expand Down
1 change: 0 additions & 1 deletion Floofbot/Handlers/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ private async Task HandleCommandAsync(SocketMessage s)
{
prefix = BotConfigFactory.Config.Prefix;
}

bool hasValidPrefix = msg.HasMentionPrefix(_client.CurrentUser, ref argPos) || msg.HasStringPrefix(prefix, ref argPos);
string strippedCommandName = msg.Content.Substring(argPos).Split()[0];
bool hasValidStart = !string.IsNullOrEmpty(strippedCommandName) && Regex.IsMatch(strippedCommandName, @"^[0-9]?[a-z]+\??$", RegexOptions.IgnoreCase);
Expand Down
2 changes: 1 addition & 1 deletion Floofbot/Migrations/20200512215812_modmail.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Floofbot/Migrations/20200512215812_modmail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Floofbot.Migrations
{
public partial class modmail : Migration
public partial class Modmail : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
Expand Down
8 changes: 5 additions & 3 deletions Floofbot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

static async Task Main(string[] args)
{
string botDirectory = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

Check warning on line 20 in Floofbot/Program.cs

View workflow job for this annotation

GitHub Actions / build

'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.

Check warning on line 20 in Floofbot/Program.cs

View workflow job for this annotation

GitHub Actions / build

'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.

Check warning on line 20 in Floofbot/Program.cs

View workflow job for this annotation

GitHub Actions / build

'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.
string _configPath;
if (args.Length == 1)
_configPath = args[0];
Expand All @@ -31,7 +31,7 @@
string token = BotConfigFactory.Config.Token;
if (string.IsNullOrEmpty(token))
{
Console.WriteLine("Error: the Token field in app.config must contain a valid Discord bot token.");
Console.WriteLine("Error: the Token field in config.yaml must contain a valid Discord bot token.");
Environment.Exit(1);
}
await new Program().MainAsync(token);
Expand Down Expand Up @@ -62,8 +62,10 @@
new DiscordSocketConfig()
{
LogLevel = LogSeverity.Info,
MessageCacheSize = 1000
});
MessageCacheSize = 1000,
AlwaysDownloadUsers = true,
GatewayIntents = GatewayIntents.All
}) ;

try
{
Expand Down
39 changes: 19 additions & 20 deletions Floofbot/Services/EventHandlerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ public Task MessageUpdated(Cacheable<IMessage, ulong> before, SocketMessage afte
});
return Task.CompletedTask;
}
public Task MessageDeleted(Cacheable<IMessage, ulong> before, ISocketMessageChannel chan)
public Task MessageDeleted(Cacheable<IMessage, ulong> before, Cacheable<IMessageChannel, ulong> channel)
{
IMessageChannel chan = channel.Value;
var _ = Task.Run(async () =>
{
try
Expand All @@ -267,23 +268,25 @@ public Task MessageDeleted(Cacheable<IMessage, ulong> before, ISocketMessageChan
if (message.Author.IsBot)
return;

var channel = chan as ITextChannel; // channel null, dm message?
if (channel == null)
if (chan == null)
return;

if ((IsToggled(channel.Guild)) == false) // not toggled on
IGuildChannel messageChannel = message.Channel as IGuildChannel;
IGuild guild = messageChannel.Guild;

if ((IsToggled(guild)) == false) // not toggled on
return;


Discord.ITextChannel logChannel = await GetChannel(channel.Guild, "MessageDeletedChannel");
Discord.ITextChannel logChannel = await GetChannel(guild, "MessageDeletedChannel");
if (logChannel == null)
return;

var embed = new EmbedBuilder();

embed.WithTitle($"⚠️ Message Deleted | {message.Author.Username}#{message.Author.Discriminator}")
.WithColor(Color.Gold)
.WithDescription($"{message.Author.Mention} ({message.Author.Id}) has had their message deleted in {channel.Mention}!")
.WithDescription($"{message.Author.Mention} ({message.Author.Id}) has had their message deleted in {MentionUtils.MentionChannel(chan.Id)}!")
.WithCurrentTimestamp()
.WithFooter($"user_message_deleted user_messagelog {message.Author.Id}");
if (message.Content.Length > 0)
Expand Down Expand Up @@ -437,8 +440,10 @@ public Task UserUnbanned(IUser user, IGuild guild)
return Task.CompletedTask;

}
public Task UserJoined(IGuildUser user)
public Task UserJoined(SocketGuildUser sUser)
{
SocketGuild guild = sUser.Guild;
IGuildUser user = guild.GetUser(sUser.Id);
var _ = Task.Run(async () =>
{
try
Expand Down Expand Up @@ -482,7 +487,7 @@ public Task UserJoined(IGuildUser user)
});
return Task.CompletedTask;
}
public Task UserLeft(IGuildUser user)
public Task UserLeft(SocketGuild guild, SocketUser user)
{
var _ = Task.Run(async () =>
{
Expand All @@ -491,27 +496,18 @@ public Task UserLeft(IGuildUser user)
if (user.IsBot)
return;

await _userRoleRetentionService.LogUserRoles(user);

if ((IsToggled(user.Guild)) == false)
if ((IsToggled(guild)) == false)
return;

Discord.ITextChannel channel = await GetChannel(user.Guild, "UserLeftChannel");
Discord.ITextChannel channel = await GetChannel(guild, "UserLeftChannel");
if (channel == null)
return;

var embed = new EmbedBuilder();
embed.WithTitle($"❌ User Left | {user.Username}#{user.Discriminator}")
.WithColor(Color.Red)
.WithDescription($"{user.Mention} | ``{user.Id}``");
if (user.JoinedAt != null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what happened to JoinedAt? I can't seem to find older docs on previous versions of Discord.NET, and there is no entry for JoinedAt for version 3.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's changed from guilduser to socketuser, this no longer knows the join date as the user isn't associated with a guild, couldn't think of alternative solution but to remove it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really late, but you can actually get the SocketGuildUser by using GetUser.

{
DateTimeOffset userJoined = ((DateTimeOffset)user.JoinedAt);
TimeSpan interval = DateTime.UtcNow - userJoined.DateTime;
string day_word = interval.Days == 1 ? "day" : "days";
embed.AddField("Joined Server", userJoined.ToString("ddd, dd MMM yyyy"), true);
embed.AddField("Time at Server", $"{interval.Days} {day_word}", true);
}
embed.WithFooter($"user_leave user_joinlog {user.Id}")
.WithCurrentTimestamp();

Expand Down Expand Up @@ -603,8 +599,9 @@ public Task UserUpdated(SocketUser before, SocketUser userAfter)

}

public Task GuildMemberUpdated(SocketGuildUser before, SocketGuildUser after)
public Task GuildMemberUpdated(Cacheable<SocketGuildUser, ulong> _before, SocketGuildUser after)
{
SocketGuildUser before = _before.Value;
var _ = Task.Run(async () =>
{
try
Expand Down Expand Up @@ -656,6 +653,8 @@ public Task GuildMemberUpdated(SocketGuildUser before, SocketGuildUser after)
}
else if (before.Roles.Count != after.Roles.Count)
{
await _userRoleRetentionService.LogUserRoles(before as IGuildUser);

List<SocketRole> beforeRoles = new List<SocketRole>(before.Roles);
List<SocketRole> afterRoles = new List<SocketRole>(after.Roles);
List<SocketRole> roleDifference = new List<SocketRole>();
Expand Down
25 changes: 11 additions & 14 deletions Floofbot/Services/NicknameAlertService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public async Task HandleBadNickname(SocketGuildUser badUser, IGuild guild, List<

}

public async Task OnReactionAdded(Cacheable<IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
public async Task OnReactionAdded(Cacheable<IUserMessage, ulong> message, Cacheable<IMessageChannel, ulong> channel, SocketReaction reaction)
{
var msg = message.Value as IUserMessage;
var chan = channel as ITextChannel;
var chan = channel.Value as ITextChannel;

if (reaction.User.Value.IsBot || msg == null || chan == null)
return;
Expand Down Expand Up @@ -100,11 +100,11 @@ public async Task OnReactionAdded(Cacheable<IUserMessage, ulong> message, ISocke

await badUser.SendMessageAsync("", false, builder.Build());
await badUser.Guild.AddBanAsync(badUser, 0, $"{moderator.Username}#{moderator.Discriminator} ({moderator.Id}) -> Inappropriate Name");
await channel.SendMessageAsync($"Got it! I banned {badUser.Username}#{badUser.Discriminator}!");
await chan.SendMessageAsync($"Got it! I banned {badUser.Username}#{badUser.Discriminator}!");
}
catch (Exception ex)
{
await channel.SendMessageAsync("Unable to ban user. Do I have the permissions?");
await chan.SendMessageAsync("Unable to ban user. Do I have the permissions?");
Log.Error("Unable to ban user for bad name: " + ex);
}
alertMessageIdsDic.Remove(msg.Id);
Expand Down Expand Up @@ -132,12 +132,11 @@ public async Task OnReactionAdded(Cacheable<IUserMessage, ulong> message, ISocke
builder.AddField("Reason", "Warned by BOT for an inappropriate name");
builder.Color = Color.DarkOrange;
await badUser.SendMessageAsync("", false, builder.Build());

await channel.SendMessageAsync($"Got it! I warned {badUser.Username}#{badUser.Discriminator}!");
await chan.SendMessageAsync($"Got it! I warned {badUser.Username}#{badUser.Discriminator}!");
}
catch (Exception ex)
{
await channel.SendMessageAsync("Unable to warn user. Do I have the permissions?");
await chan.SendMessageAsync("Unable to warn user. Do I have the permissions?");
Log.Error("Unable to warn user for bad name: " + ex);
}
alertMessageIdsDic.Remove(msg.Id);
Expand All @@ -154,14 +153,12 @@ public async Task OnReactionAdded(Cacheable<IUserMessage, ulong> message, ISocke
builder.AddField("Reason", "Kicked by BOT for an inappropriate name");
builder.Color = Color.DarkOrange;
await badUser.SendMessageAsync("", false, builder.Build());

await badUser.KickAsync($"{badUser.Username}#{badUser.Discriminator} -> Inappropriate Name");

await channel.SendMessageAsync($"Got it! I kicked {badUser.Username}#{badUser.Discriminator}!");
await chan.SendMessageAsync($"Got it! I kicked {badUser.Username}#{badUser.Discriminator}!");
}
catch (Exception ex)
{
await channel.SendMessageAsync("Unable to kick user. Do I have the permissions?");
await chan.SendMessageAsync("Unable to kick user. Do I have the permissions?");
Log.Error("Unable to kick user for bad name: " + ex);
}
alertMessageIdsDic.Remove(msg.Id);
Expand All @@ -171,18 +168,18 @@ public async Task OnReactionAdded(Cacheable<IUserMessage, ulong> message, ISocke
try
{
await badUser.Guild.GetUser(badUser.Id).ModifyAsync(user => user.Nickname = "");
await channel.SendMessageAsync($"Got it! I removed {badUser.Username}#{badUser.Discriminator}'s nickname!");
await chan.SendMessageAsync($"Got it! I removed {badUser.Username}#{badUser.Discriminator}'s nickname!");
}
catch (Exception ex)
{
await channel.SendMessageAsync("Unable to remove their nickname. Do I have the permissions?");
await chan.SendMessageAsync("Unable to remove their nickname. Do I have the permissions?");
Log.Error("Unable to remove nickname for bad name: " + ex);
}
alertMessageIdsDic.Remove(msg.Id);
}
else if (reaction.Emote.Name.Equals(NO_ACTION_EMOJI.Name))
{
await channel.SendMessageAsync($"Got it! I took no action against {badUser.Username}#{badUser.Discriminator}!");
await chan.SendMessageAsync($"Got it! I took no action against {badUser.Username}#{badUser.Discriminator}!");
alertMessageIdsDic.Remove(msg.Id);
}
return;
Expand Down
2 changes: 2 additions & 0 deletions Floofbot/Services/UserRoleRetentionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -57,6 +58,7 @@ public string GetUserRoles(IGuildUser user)
}
public async Task RestoreUserRoles(IGuildUser user)
{

var oldUserRoles = GetUserRoles(user);

if (oldUserRoles != null) // user actually had old roles
Expand Down
6 changes: 4 additions & 2 deletions Floofbot/Services/WelcomeGateService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Discord.WebSocket;
using Discord;
using Discord.WebSocket;
using Floofbot.Services.Repository;
using Floofbot.Services.Repository.Models;
using Serilog;
Expand All @@ -14,8 +15,9 @@ public WelcomeGateService(FloofDataContext floofDb)
{
_floofDb = floofDb;
}
public async Task HandleWelcomeGate(SocketGuildUser before, SocketGuildUser after)
public async Task HandleWelcomeGate(Cacheable<SocketGuildUser, ulong> _before, SocketGuildUser after)
{
SocketGuildUser before = _before.Value;
if (before.IsPending == after.IsPending) // no welcome gate change
return;
FloofDataContext floofDb = new FloofDataContext();
Expand Down
4 changes: 2 additions & 2 deletions Floofbot/Services/WordFilterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public List<string> filteredWordsInName(FloofDataContext floofDb, string message
}

DateTime currentTime = DateTime.Now;
if (_lastRefreshedTime == null || currentTime.Subtract(_lastRefreshedTime).TotalMinutes >= 30)
if (currentTime.Subtract(_lastRefreshedTime).TotalMinutes >= 30)
{
_filteredWords = floofDb.FilteredWords.AsQueryable()
.Where(x => x.ServerId == serverId).ToList();
Expand Down Expand Up @@ -61,7 +61,7 @@ public bool hasFilteredWord(FloofDataContext floofDb, string messageContent, ulo
}

DateTime currentTime = DateTime.Now;
if (_lastRefreshedTime == null || currentTime.Subtract(_lastRefreshedTime).TotalMinutes >= 30)
if (currentTime.Subtract(_lastRefreshedTime).TotalMinutes >= 30)
{
_filteredWords = floofDb.FilteredWords.AsQueryable()
.Where(x => x.ServerId == serverId).ToList();
Expand Down
Loading