public async Task VerboseActCheck() { await TempActions.CheckTempActs(Context.Client, true); await ReplyAsync("Checked temp acts. Info is in console"); }
public async Task NewInput() { try { string input = Console.ReadLine(); List <string> splitInput = input.Split(' ').ToList(); switch (splitInput[0].ToLower()) { case "messageowners": splitInput.RemoveAt(0); string message = ""; foreach (string word in splitInput) { message += " " + word; } List <SocketUser> owners = new List <SocketUser>(); foreach (SocketGuild guild in client.Guilds) { if (!owners.Contains(guild.Owner)) { owners.Add(guild.Owner); } } foreach (SocketUser owner in owners) { owner.TryNotify(message); } await new LogMessage(LogSeverity.Info, "Console", "Messaged guild owners:" + message).Log(); break; case "checktempbans": await TempActions.TempActChecker(client, true); await(new LogMessage(LogSeverity.Info, "Console", "Checked temp-actions")).Log(); break; case "shutdown": case "shut down": await client.SetGameAsync("restarting"); Environment.Exit(0); break; case "stats": case "statistics": Console.Write($"Part of {client.Guilds.Count} discord guilds "); List <Infraction> infractions = new List <Infraction>(); ulong members = 0; int i = 0; foreach (SocketGuild guild in client.Guilds) { if (i == 3) { members += (ulong)guild.MemberCount; } var collection = guild.GetInfractionsCollection(false); if (collection != null) { using (var cursor = collection.Find(new BsonDocument()).ToCursor()) { foreach (var doc in cursor.ToList()) { foreach (Infraction infraction in BsonSerializer.Deserialize <UserInfractions>(doc).infractions) { infractions.Add(infraction); } } } } } Console.Write($"with a total of {members} users. There are {infractions.Count} total infractions "); InfractionInfo data = new InfractionInfo(infractions, 0, false); Console.WriteLine($"with {data.infractionsToday.count} infractions given in the last 24 hours"); Console.Write("> "); break; default: await new LogMessage(LogSeverity.Warning, "Console", "Command not recognized").Log(); break; } } catch (Exception e) { _ = new LogMessage(LogSeverity.Error, "Main", "Console didn't work", e).Log(); } Console.Beep(); _ = NewInput(); }
public static async Task Main(string[] args) { var baseDir = AppDomain.CurrentDomain.BaseDirectory; var logConfig = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Console(theme: AnsiConsoleTheme.Code) .WriteTo.File($"{baseDir}/log.txt", rollingInterval: RollingInterval.Day); ExceptionLogging.logger = logConfig.CreateLogger(); await new LogMessage(LogSeverity.Info, "App", $"Starting with logging at {baseDir}").Log(); await DataManipulator.MapTypes(); #if DEBUG BotInfo.debug = true; #endif DotNetEnv.Env.Load($"{baseDir}/BotCatMaxy.env"); dbClient = new MongoClient(Environment.GetEnvironmentVariable("DataToken")); var config = new DiscordSocketConfig { AlwaysDownloadUsers = true, //going to keep here for new guilds added, but seems to be broken for startup per https://github.com/discord-net/Discord.Net/issues/1646 ConnectionTimeout = 6000, MessageCacheSize = 120, ExclusiveBulkDelete = false, DefaultRetryMode = RetryMode.AlwaysRetry, GatewayIntents = GatewayIntents.GuildBans | GatewayIntents.GuildMembers | GatewayIntents.GuildMessageReactions | GatewayIntents.GuildMessages | GatewayIntents.DirectMessages | GatewayIntents.Guilds }; //Sets up the events _client = new DiscordSocketClient(config); _client.Log += ExceptionLogging.Log; _client.Ready += Ready; //Delete once https://github.com/discord-net/Discord.Net/issues/1646 is fixed _client.GuildAvailable += HandleGuildAvailable; await _client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("DiscordToken")); await _client.StartAsync(); SettingsCache cacher = new SettingsCache(_client); //Gets build date const string BuildVersionMetadataPrefix = "+build"; DateTime buildDate = new DateTime(); var attribute = Assembly.GetExecutingAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>(); if (attribute?.InformationalVersion != null) { var value = attribute.InformationalVersion; var index = value.IndexOf(BuildVersionMetadataPrefix); if (index > 0) { value = value.Substring(index + BuildVersionMetadataPrefix.Length); if (DateTime.TryParseExact(value, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var result)) { buildDate = result.ToUniversalTime(); } } } string version = args.ElementAtOrDefault(0) ?? "unknown"; await new LogMessage(LogSeverity.Info, "Main", $"Starting with version {version}, built {buildDate.ToShortDateString()}, {(DateTime.UtcNow - buildDate).LimitedHumanize()} ago").Log(); StatusManager statusManager = new StatusManager(_client, version); await new LogMessage(LogSeverity.Info, "Mongo", $"Connected to cluster {dbClient.Cluster.ClusterId} with {dbClient.ListDatabases().ToList().Count} databases").Log(); var serviceConfig = new CommandServiceConfig { DefaultRunMode = RunMode.Async, IgnoreExtraArgs = true }; CommandService service = new CommandService(serviceConfig); CommandHandler handler = new CommandHandler(_client, service); DynamicSlowmode dynamicSlowmode = new DynamicSlowmode(_client); LoggingHandler logger = new LoggingHandler(_client); TempActions tempActions = new TempActions(_client); FilterHandler filter = new FilterHandler(_client); //Debug info await new LogMessage(LogSeverity.Info, "Main", "Setup complete").Log(); await Task.Delay(-1); }
public async Task MainAsync(string version = null, string beCanary = null) { var config = new DiscordSocketConfig { AlwaysDownloadUsers = true, MessageCacheSize = 120, ExclusiveBulkDelete = false }; //Maps all the classes try { BsonClassMap.RegisterClassMap <List <Infraction> >(); BsonClassMap.RegisterClassMap <ModerationSettings>(); BsonClassMap.RegisterClassMap <UserInfractions>(); BsonClassMap.RegisterClassMap <LogSettings>(); BsonClassMap.RegisterClassMap <Infraction>(); BsonClassMap.RegisterClassMap <TempAct>(); BsonClassMap.RegisterClassMap <BadWord>(); } catch (Exception e) { await new LogMessage(LogSeverity.Critical, "Main", "Unable to map type", e).Log(); } //Sets up the events _client = new DiscordSocketClient(config); _client.Log += Utilities.Log; _client.Ready += Ready; if (beCanary != null && beCanary.ToLower() == "canary") { await _client.LoginAsync(TokenType.Bot, HiddenInfo.testToken); dbClient = new MongoClient(HiddenInfo.debugDB); } else { dbClient ??= new MongoClient(HiddenInfo.mainDB); await _client.LoginAsync(TokenType.Bot, HiddenInfo.Maintoken); } await _client.StartAsync(); const string BuildVersionMetadataPrefix = "+build"; DateTime buildDate = new DateTime(); var attribute = Assembly.GetExecutingAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>(); if (attribute?.InformationalVersion != null) { var value = attribute.InformationalVersion; var index = value.IndexOf(BuildVersionMetadataPrefix); if (index > 0) { value = value.Substring(index + BuildVersionMetadataPrefix.Length); if (DateTime.TryParseExact(value, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var result)) { buildDate = result.ToLocalTime(); } } } if (version.NotEmpty()) { await new LogMessage(LogSeverity.Info, "Main", $"Starting with version {version} built {buildDate.ToShortDateString()}, {(DateTime.Now - buildDate).LimitedHumanize()} ago").Log(); await _client.SetGameAsync("version " + version); } else { await new LogMessage(LogSeverity.Info, "Main", $"Starting with no version num built {buildDate.ToShortDateString()}, {(DateTime.Now - buildDate).LimitedHumanize()} ago").Log(); } CommandService service = new CommandService(); CommandHandler handler = new CommandHandler(_client, service); Logging logger = new Logging(_client); TempActions tempActions = new TempActions(_client); Filter filter = new Filter(_client); //ConsoleReader consoleReader = new ConsoleReader(_client); //Debug info await new LogMessage(LogSeverity.Info, "Main", "Setup complete").Log(); await Task.Delay(-1); }