1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-06 22:16:29 +03:00

ton of stuff

- new command handler
- multilanguage support
- time out support
- responses
- a ton of stuff
This commit is contained in:
l1ttleO 2022-01-18 22:38:15 +05:00
parent 1c9caf6d75
commit f30485dd71
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
29 changed files with 1686 additions and 520 deletions

View file

@ -1,4 +1,5 @@
using System.Text.Json;
using System.Globalization;
using System.Text.Json;
using Discord;
using Discord.WebSocket;
@ -6,9 +7,6 @@ namespace Boyfriend;
public static class Boyfriend {
public static void Main()
=> Init().GetAwaiter().GetResult();
private static readonly DiscordSocketConfig Config = new() {
MessageCacheSize = 250,
GatewayIntents = GatewayIntents.All
@ -18,15 +16,19 @@ public static class Boyfriend {
private static readonly Dictionary<ulong, GuildConfig> GuildConfigDictionary = new();
public static void Main() {
Init().GetAwaiter().GetResult();
}
private static async Task Init() {
Client.Log += Log;
var token = (await File.ReadAllTextAsync("token.txt")).Trim();
await Client.LoginAsync(TokenType.Bot, token);
await Client.StartAsync();
await Client.SetActivityAsync(new Game("Retrospecter - Electrospasm", ActivityType.Listening));
await Client.SetActivityAsync(new Game("Retrospecter - Chiller", ActivityType.Listening));
await new EventHandler().InitEvents();
new EventHandler().InitEvents();
await Task.Delay(-1);
}
@ -45,29 +47,28 @@ public static class Boyfriend {
try {
config = await JsonSerializer.DeserializeAsync<GuildConfig>(openStream) ?? throw new Exception();
} catch (JsonException) {
config = new GuildConfig(guild.Id, "ru", "!", false, true, true, 0, 0, 0);
Messages.Culture = new CultureInfo("ru");
config = new GuildConfig(guild.Id, "ru", "!", false, true,
true, Messages.DefaultWelcomeMessage, 0, 0, 0, 0);
}
GuildConfigDictionary.Add(guild.Id, config);
}
}
public static GuildConfig GetGuildConfig(IGuild guild) {
Messages.Culture = new CultureInfo("ru");
var toReturn = GuildConfigDictionary.ContainsKey(guild.Id) ? GuildConfigDictionary[guild.Id]
: new GuildConfig(guild.Id, "ru", "!", false, true, true, 0, 0, 0);
: new GuildConfig(guild.Id, "ru", "!", false, true, true, Messages.DefaultWelcomeMessage, 0, 0, 0, 0);
if (toReturn.Id != guild.Id) throw new Exception();
return toReturn;
}
public static IGuild FindGuild(ITextChannel channel) {
foreach (var guild in Client.Guilds) {
if (guild.Channels.Any(x => x == channel)) return guild;
}
public static IGuild FindGuild(IMessageChannel channel) {
foreach (var guild in Client.Guilds)
if (guild.Channels.Any(x => x == channel))
return guild;
throw new Exception("Не удалось найти сервер по каналу!");
}
public static void ThrowFatal(Exception e) {
throw e;
throw new Exception(Messages.CouldntFindGuildByChannel);
}
}