mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-20 00:43:36 +03:00
Merge branch 'master' into mctaylors_master_merge
This commit is contained in:
commit
93507336e5
9 changed files with 97 additions and 34 deletions
27
.github/dependabot.yml
vendored
Normal file
27
.github/dependabot.yml
vendored
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# To get started with Dependabot version updates, you'll need to specify which
|
||||||
|
# package ecosystems to update and where the package manifests are located.
|
||||||
|
# Please see the documentation for all configuration options:
|
||||||
|
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions" # See documentation for possible values
|
||||||
|
directory: "/" # Location of package manifests
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
allow:
|
||||||
|
# Allow both direct and indirect updates for all packages
|
||||||
|
- dependency-type: "all"
|
||||||
|
assignees:
|
||||||
|
- "l1ttleO"
|
||||||
|
|
||||||
|
- package-ecosystem: "nuget" # See documentation for possible values
|
||||||
|
directory: "/Boyfriend" # Location of package manifests
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
allow:
|
||||||
|
# Allow both direct and indirect updates for all packages
|
||||||
|
- dependency-type: "all"
|
||||||
|
# Add assignees
|
||||||
|
assignees:
|
||||||
|
- "l1ttleO"
|
44
.github/workflows/codeql.yml
vendored
Normal file
44
.github/workflows/codeql.yml
vendored
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
name: "CodeQL"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "master" ]
|
||||||
|
schedule:
|
||||||
|
- cron: '45 7 * * 2'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'csharp' ]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
queries: +security-extended,security-and-quality
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v2
|
||||||
|
with:
|
||||||
|
category: "/language:${{matrix.language}}"
|
|
@ -83,7 +83,7 @@ public static class Boyfriend {
|
||||||
if (!RemovedRolesDictionary.ContainsKey(id))
|
if (!RemovedRolesDictionary.ContainsKey(id))
|
||||||
RemovedRolesDictionary.Add(id, new Dictionary<ulong, ReadOnlyCollection<ulong>>());
|
RemovedRolesDictionary.Add(id, new Dictionary<ulong, ReadOnlyCollection<ulong>>());
|
||||||
|
|
||||||
if (GuildConfigDictionary.ContainsKey(id)) return GuildConfigDictionary[id];
|
if (GuildConfigDictionary.TryGetValue(id, out var cfg)) return cfg;
|
||||||
|
|
||||||
var path = $"config_{id}.json";
|
var path = $"config_{id}.json";
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public static class Boyfriend {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<ulong, ReadOnlyCollection<ulong>> GetRemovedRoles(ulong id) {
|
public static Dictionary<ulong, ReadOnlyCollection<ulong>> GetRemovedRoles(ulong id) {
|
||||||
if (RemovedRolesDictionary.ContainsKey(id)) return RemovedRolesDictionary[id];
|
if (RemovedRolesDictionary.TryGetValue(id, out var dict)) return dict;
|
||||||
|
|
||||||
var path = $"removedroles_{id}.json";
|
var path = $"removedroles_{id}.json";
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ public static class Boyfriend {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SocketGuild FindGuild(ulong channel) {
|
public static SocketGuild FindGuild(ulong channel) {
|
||||||
if (GuildCache.ContainsKey(channel)) return GuildCache[channel];
|
if (GuildCache.TryGetValue(channel, out var gld)) return gld;
|
||||||
foreach (var guild in Client.Guilds) {
|
foreach (var guild in Client.Guilds) {
|
||||||
// ReSharper disable once LoopCanBeConvertedToQuery
|
// ReSharper disable once LoopCanBeConvertedToQuery
|
||||||
foreach (var x in guild.Channels)
|
foreach (var x in guild.Channels)
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
<LangVersion>default</LangVersion>
|
<LangVersion>default</LangVersion>
|
||||||
<Title>Boyfriend</Title>
|
<Title>Boyfriend</Title>
|
||||||
<Authors>l1ttle</Authors>
|
<Authors>l1ttle</Authors>
|
||||||
<PackageProjectUrl>https://git.cavej376.xyz/Octol1ttle/Boyfriend-CSharp</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/l1ttleO/Boyfriend-CSharp</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://git.cavej376.xyz/Octol1ttle/Boyfriend-CSharp</RepositoryUrl>
|
<RepositoryUrl>https://github.com/l1ttleO/Boyfriend-CSharp</RepositoryUrl>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<PackageVersion>1.0.1</PackageVersion>
|
<PackageVersion>1.0.0</PackageVersion>
|
||||||
<PackageLicenseUrl>https://git.cavej376.xyz/Octol1ttle/Boyfriend-CSharp/src/branch/master/LICENSE</PackageLicenseUrl>
|
<PackageLicenseUrl>https://github.com/l1ttleO/Boyfriend-CSharp/blob/master/LICENSE</PackageLicenseUrl>
|
||||||
<NeutralLanguage>en</NeutralLanguage>
|
<NeutralLanguage>en</NeutralLanguage>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using Boyfriend.Commands;
|
using Boyfriend.Commands;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
@ -14,14 +13,14 @@ public sealed class CommandProcessor {
|
||||||
private const string NoAccess = ":no_entry_sign: ";
|
private const string NoAccess = ":no_entry_sign: ";
|
||||||
private const string CantInteract = ":vertical_traffic_light: ";
|
private const string CantInteract = ":vertical_traffic_light: ";
|
||||||
|
|
||||||
|
private const string Mention = "<@855023234407333888>";
|
||||||
|
|
||||||
public static readonly ICommand[] Commands = {
|
public static readonly ICommand[] Commands = {
|
||||||
new BanCommand(), new ClearCommand(), new HelpCommand(),
|
new BanCommand(), new ClearCommand(), new HelpCommand(),
|
||||||
new KickCommand(), new MuteCommand(), new PingCommand(),
|
new KickCommand(), new MuteCommand(), new PingCommand(),
|
||||||
new SettingsCommand(), new UnbanCommand(), new UnmuteCommand()
|
new SettingsCommand(), new UnbanCommand(), new UnmuteCommand()
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly Dictionary<string, Regex> RegexCache = new();
|
|
||||||
private static readonly Regex MentionRegex = new(Regex.Escape("<@855023234407333888>"), RegexOptions.Compiled);
|
|
||||||
private readonly StringBuilder _stackedPrivateFeedback = new();
|
private readonly StringBuilder _stackedPrivateFeedback = new();
|
||||||
private readonly StringBuilder _stackedPublicFeedback = new();
|
private readonly StringBuilder _stackedPublicFeedback = new();
|
||||||
private readonly StringBuilder _stackedReplyMessage = new();
|
private readonly StringBuilder _stackedReplyMessage = new();
|
||||||
|
@ -46,16 +45,10 @@ public sealed class CommandProcessor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Regex regex;
|
|
||||||
if (RegexCache.ContainsKey(config["Prefix"])) { regex = RegexCache[config["Prefix"]]; } else {
|
|
||||||
regex = new Regex(Regex.Escape(config["Prefix"]), RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
|
||||||
RegexCache.Add(config["Prefix"], regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
var list = Context.Message.Content.Split("\n");
|
var list = Context.Message.Content.Split("\n");
|
||||||
var cleanList = Context.Message.CleanContent.Split("\n");
|
var cleanList = Context.Message.CleanContent.Split("\n");
|
||||||
for (var i = 0; i < list.Length; i++) {
|
for (var i = 0; i < list.Length; i++) {
|
||||||
RunCommandOnLine(list[i], cleanList[i], regex);
|
RunCommandOnLine(list[i], cleanList[i], config["Prefix"]);
|
||||||
if (_serverBlacklisted) {
|
if (_serverBlacklisted) {
|
||||||
await Context.Message.ReplyAsync(Messages.ServerBlacklisted);
|
await Context.Message.ReplyAsync(Messages.ServerBlacklisted);
|
||||||
return;
|
return;
|
||||||
|
@ -78,20 +71,21 @@ public sealed class CommandProcessor {
|
||||||
SendFeedbacks();
|
SendFeedbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RunCommandOnLine(string line, string cleanLine, Regex regex) {
|
private void RunCommandOnLine(string line, string cleanLine, string prefix) {
|
||||||
|
var prefixed = line[..prefix.Length] == prefix;
|
||||||
|
if (!prefixed && line[..Mention.Length] is not Mention) return;
|
||||||
foreach (var command in Commands) {
|
foreach (var command in Commands) {
|
||||||
var lineNoMention = regex.Replace(MentionRegex.Replace(line, "", 1), "", 1);
|
var lineNoMention = line.Remove(0, prefixed ? prefix.Length : Mention.Length);
|
||||||
if (lineNoMention == line
|
if (!command.Aliases.Contains(lineNoMention.Trim().Split()[0])) continue;
|
||||||
|| !command.Aliases.Contains(lineNoMention.Trim().ToLower().Split()[0]))
|
|
||||||
continue;
|
|
||||||
if (Utils.IsServerBlacklisted(Context.Guild)) {
|
if (Utils.IsServerBlacklisted(Context.Guild)) {
|
||||||
_serverBlacklisted = true;
|
_serverBlacklisted = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var args = line.Split().Skip(lineNoMention.StartsWith(" ") ? 2 : 1).ToArray();
|
var args = lineNoMention.Trim().Split().Skip(1).ToArray();
|
||||||
var cleanArgs = cleanLine.Split().Skip(lineNoMention.StartsWith(" ") ? 2 : 1).ToArray();
|
var cleanArgs = cleanLine.Split().Skip(lineNoMention.StartsWith(" ") ? 2 : 1).ToArray();
|
||||||
_tasks.Add(command.RunAsync(this, args, cleanArgs));
|
_tasks.Add(command.RunAsync(this, args, cleanArgs));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@ public sealed class MuteCommand : ICommand {
|
||||||
|
|
||||||
var rolesRemoved = Boyfriend.GetRemovedRoles(cmd.Context.Guild.Id);
|
var rolesRemoved = Boyfriend.GetRemovedRoles(cmd.Context.Guild.Id);
|
||||||
|
|
||||||
if (rolesRemoved.ContainsKey(toMute.Id)) {
|
if (rolesRemoved.TryGetValue(toMute.Id, out var mutedRemovedRoles)) {
|
||||||
foreach (var roleId in rolesRemoved[toMute.Id]) await toMute.AddRoleAsync(roleId);
|
foreach (var roleId in mutedRemovedRoles) await toMute.AddRoleAsync(roleId);
|
||||||
rolesRemoved.Remove(toMute.Id);
|
rolesRemoved.Remove(toMute.Id);
|
||||||
cmd.ConfigWriteScheduled = true;
|
cmd.ConfigWriteScheduled = true;
|
||||||
cmd.Reply(Messages.RolesReturned, ":warning: ");
|
cmd.Reply(Messages.RolesReturned, ":warning: ");
|
||||||
|
|
|
@ -110,10 +110,9 @@ public sealed class SettingsCommand : ICommand {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (value is "reset" or "default") {
|
if (value is "reset" or "default") {
|
||||||
if (selectedSetting is "WelcomeMessage")
|
config[selectedSetting] = selectedSetting is "WelcomeMessage"
|
||||||
config[selectedSetting] = Messages.DefaultWelcomeMessage;
|
? Messages.DefaultWelcomeMessage
|
||||||
else
|
: Boyfriend.DefaultConfig[selectedSetting];
|
||||||
config[selectedSetting] = Boyfriend.DefaultConfig[selectedSetting];
|
|
||||||
} else {
|
} else {
|
||||||
if (value == config[selectedSetting]) {
|
if (value == config[selectedSetting]) {
|
||||||
cmd.Reply(string.Format(Messages.SettingsNothingChanged, localizedSelectedSetting, formattedValue),
|
cmd.Reply(string.Format(Messages.SettingsNothingChanged, localizedSelectedSetting, formattedValue),
|
||||||
|
|
|
@ -23,8 +23,8 @@ public sealed class UnmuteCommand : ICommand {
|
||||||
if (role != null && toUnmute.Roles.Contains(role)) {
|
if (role != null && toUnmute.Roles.Contains(role)) {
|
||||||
var rolesRemoved = Boyfriend.GetRemovedRoles(cmd.Context.Guild.Id);
|
var rolesRemoved = Boyfriend.GetRemovedRoles(cmd.Context.Guild.Id);
|
||||||
|
|
||||||
if (rolesRemoved.ContainsKey(toUnmute.Id)) {
|
if (rolesRemoved.TryGetValue(toUnmute.Id, out var unmutedRemovedRoles)) {
|
||||||
await toUnmute.AddRolesAsync(rolesRemoved[toUnmute.Id]);
|
await toUnmute.AddRolesAsync(unmutedRemovedRoles);
|
||||||
rolesRemoved.Remove(toUnmute.Id);
|
rolesRemoved.Remove(toUnmute.Id);
|
||||||
cmd.ConfigWriteScheduled = true;
|
cmd.ConfigWriteScheduled = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ public static class Utils {
|
||||||
|
|
||||||
public static SocketRole? GetMuteRole(SocketGuild guild) {
|
public static SocketRole? GetMuteRole(SocketGuild guild) {
|
||||||
var id = ulong.Parse(Boyfriend.GetGuildConfig(guild.Id)["MuteRole"]);
|
var id = ulong.Parse(Boyfriend.GetGuildConfig(guild.Id)["MuteRole"]);
|
||||||
if (MuteRoleCache.ContainsKey(id)) return MuteRoleCache[id];
|
if (MuteRoleCache.TryGetValue(id, out var cachedMuteRole)) return cachedMuteRole;
|
||||||
SocketRole? role = null;
|
SocketRole? role = null;
|
||||||
foreach (var x in guild.Roles) {
|
foreach (var x in guild.Roles) {
|
||||||
if (x.Id != id) continue;
|
if (x.Id != id) continue;
|
||||||
|
@ -88,7 +88,6 @@ public static class Utils {
|
||||||
await channel.SendMessageAsync(text, false, null, null, allowRoles ? AllowRoles : AllowedMentions.None);
|
await channel.SendMessageAsync(text, false, null, null, allowRoles ? AllowRoles : AllowedMentions.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static RequestOptions GetRequestOptions(string reason) {
|
public static RequestOptions GetRequestOptions(string reason) {
|
||||||
var options = RequestOptions.Default;
|
var options = RequestOptions.Default;
|
||||||
options.AuditLogReason = reason;
|
options.AuditLogReason = reason;
|
||||||
|
@ -98,7 +97,7 @@ public static class Utils {
|
||||||
public static string GetMessage(string name) {
|
public static string GetMessage(string name) {
|
||||||
var propertyName = name;
|
var propertyName = name;
|
||||||
name = $"{Messages.Culture}/{name}";
|
name = $"{Messages.Culture}/{name}";
|
||||||
if (ReflectionMessageCache.ContainsKey(name)) return ReflectionMessageCache[name];
|
if (ReflectionMessageCache.TryGetValue(name, out var cachedMessage)) return cachedMessage;
|
||||||
|
|
||||||
var toReturn =
|
var toReturn =
|
||||||
typeof(Messages).GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null)
|
typeof(Messages).GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Static)?.GetValue(null)
|
||||||
|
|
Loading…
Add table
Reference in a new issue