mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-06 22:16:29 +03:00
more stuff. yeah
This commit is contained in:
parent
382add19a3
commit
270fba5c3c
13 changed files with 301 additions and 116 deletions
|
@ -1,33 +1,62 @@
|
|||
using Discord;
|
||||
using System.Text.Json;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace Boyfriend;
|
||||
public static class Boyfriend {
|
||||
|
||||
public static void Main()
|
||||
=> Init().GetAwaiter().GetResult();
|
||||
public static class Boyfriend {
|
||||
|
||||
private static readonly DiscordSocketConfig Config = new() {
|
||||
MessageCacheSize = 250,
|
||||
GatewayIntents = GatewayIntents.All
|
||||
};
|
||||
public static readonly DiscordSocketClient Client = new(Config);
|
||||
public static void Main()
|
||||
=> Init().GetAwaiter().GetResult();
|
||||
|
||||
private static async Task Init() {
|
||||
Client.Log += Log;
|
||||
var token = (await File.ReadAllTextAsync("token.txt")).Trim();
|
||||
private static readonly DiscordSocketConfig Config = new() {
|
||||
MessageCacheSize = 250,
|
||||
GatewayIntents = GatewayIntents.All
|
||||
};
|
||||
|
||||
await Client.LoginAsync(TokenType.Bot, token);
|
||||
await Client.StartAsync();
|
||||
await Client.SetActivityAsync(new Game("Retrospecter - Electrospasm", ActivityType.Listening));
|
||||
public static readonly DiscordSocketClient Client = new(Config);
|
||||
|
||||
await new EventHandler().InitEvents();
|
||||
private static readonly Dictionary<ulong, GuildConfig> GuildConfigDictionary = new();
|
||||
|
||||
await Task.Delay(-1);
|
||||
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 new EventHandler().InitEvents();
|
||||
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
|
||||
private static Task Log(LogMessage msg) {
|
||||
Console.WriteLine(msg.ToString());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public static async Task SetupGuildConfigs() {
|
||||
foreach (var guild in Client.Guilds) {
|
||||
var path = "config_" + guild.Id + ".json";
|
||||
var openStream = !File.Exists(path) ? File.Create(path) : File.OpenRead(path);
|
||||
|
||||
GuildConfig config;
|
||||
try {
|
||||
config = await JsonSerializer.DeserializeAsync<GuildConfig>(openStream) ?? throw new Exception();
|
||||
} catch (JsonException) {
|
||||
config = new GuildConfig(guild.Id, "ru", "!", false);
|
||||
}
|
||||
GuildConfigDictionary.Add(guild.Id, config);
|
||||
}
|
||||
}
|
||||
|
||||
private static Task Log(LogMessage msg) {
|
||||
Console.WriteLine(msg.ToString());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
public static GuildConfig GetGuildConfig(IGuild guild) {
|
||||
GuildConfig toReturn;
|
||||
toReturn = GuildConfigDictionary.ContainsKey(guild.Id) ? GuildConfigDictionary[guild.Id]
|
||||
: new GuildConfig(guild.Id, "ru", "!", false);
|
||||
|
||||
if (toReturn.Id != guild.Id) throw new Exception();
|
||||
return toReturn;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue