private async Task StartBotAsync() { Console.WriteLine(string.Empty); //for logging visual purposes #region Discord Client Initialization _config = await _jsonMngr.GetJsonObjectAsync <Config_Json>(); _db = new DatabaseContext(_config); Console.Title = _config.Bot_Name + " Bot"; _dConfig = new DiscordSocketConfig() { LogLevel = LogSeverity.Info, AlwaysDownloadUsers = true }; _dClient = new DiscordSocketClient(_dConfig); _dClient.Log += Log; #endregion #region Commands Next Initialization _cmdServiceConfig = new CommandServiceConfig() { CaseSensitiveCommands = false, DefaultRunMode = RunMode.Async, IgnoreExtraArgs = false, LogLevel = LogSeverity.Info }; _cmdService = new CommandService(_cmdServiceConfig); _dClient.MessageReceived += HandleInput; _serviceProvider = BuildServiceProvider(); await _cmdService.AddModulesAsync(Assembly.GetEntryAssembly(), _serviceProvider); _cmdService.Log += _cmdService_Log; #endregion await _dClient.LoginAsync(TokenType.Bot, _config.Token); await _dClient.SetGameAsync($"Pokemon Ultra Sun & Moon | {_config.Prefixes[0]}help"); await _dClient.StartAsync(); await Task.Delay(-1); }
public WhitelistCommands(Config_Json cnfg, DatabaseContext db, Random rnd) { _config = cnfg; _db = db; _rnd = rnd; _eFooter = new EmbedFooterBuilder() { IconUrl = Defined.BIG_BOSS_THUMBNAIL, Text = Defined.FOOTER_MESSAGE }; _eBuilder = new EmbedBuilder { Color = Defined.Colors[_rnd.Next(Defined.Colors.Length - 1)], Footer = _eFooter }; }
public EmoteCommands(DatabaseContext db, Random rnd, JsonManager_Service jsonM, Config_Json cnfg) { _db = db; _rnd = rnd; _jsonMngr = jsonM; _config = cnfg; _eFooter = new EmbedFooterBuilder() { IconUrl = Defined.BIG_BOSS_THUMBNAIL, Text = Defined.FOOTER_MESSAGE }; _eBuilder = new EmbedBuilder { Color = Defined.Colors[_rnd.Next(Defined.Colors.Length - 1)], Footer = _eFooter }; }
public UtilityCommands(Config_Json config, DatabaseContext db, JsonManager_Service jsonParser, Random rnd) { _config = config; _db = db; _rnd = rnd; _jsonMngr = jsonParser; _eFooter = new EmbedFooterBuilder() { IconUrl = Defined.BIG_BOSS_THUMBNAIL, Text = Defined.FOOTER_MESSAGE }; _eBuilder = new EmbedBuilder { Color = Defined.Colors[_rnd.Next(Defined.Colors.Length - 1)], Footer = _eFooter }; }
public static async Task EvaluateAsync(EmbedBuilder eBuilder, Languages lng, string input, SocketCommandContext Context, DatabaseContext db, Config_Json cnfg) { switch (lng) { case Languages.CS: try { var globals = new EmulatorGlobalVariables { Context = Context, _config = cnfg, _db = db }; input = input.Replace("ReplyAsync", "Context.Channel.SendMessageAsync"); var scriptOptions = ScriptOptions.Default.WithReferences(AppDomain.CurrentDomain.GetAssemblies() .Where(x => !x.IsDynamic && !string.IsNullOrWhiteSpace(x.Location))) .WithImports("System", "System.Math", "Discord.Commands", "Discord.Net", "Discord.WebSocket", "System.Diagnostics", "System.Threading.Tasks", "System.Reflection", "System.Net", "System.Net.Http", "System.Net.Http.Headers", "System.Text", "System.Collections.Generic", "System.Linq", "System.Text.RegularExpressions", "System.IO", "EeveeBot.Classes.Database"); var script = (CSharpScript.Create(input, scriptOptions, globalsType: typeof(EmulatorGlobalVariables))); _compilsw.Start(); //counting compilation time script.Compile(); _compilsw.Stop(); _compilsw.Reset(); _exesw.Start(); //counting execution time var output = (await script.RunAsync(globals: globals)).ReturnValue.ToString(); _exesw.Stop(); _exesw.Reset(); output = output ?? "No output"; MakeEmulationEmbed(eBuilder, "C#", output, _exesw.ElapsedMilliseconds, _compilsw.ElapsedMilliseconds, true); } catch (Exception e) { var output = e.Message; MakeEmulationEmbed(eBuilder, "C#", output, 0, _compilsw.ElapsedMilliseconds, true); } break; case Languages.C: break; case Languages.CPP: break; case Languages.PY: break; case Languages.FS: break; default: break; } }
public DatabaseContext(Config_Json _cnfg) : base($"{_cnfg.Project_Path}\\{_cnfg.Bot_Name.Trim(' ')}.db4") { GetCollection <EeveeEmote>(Defined.EEVEE_EMOTES_TABLE_NAME).EnsureIndex(x => x.Id); GetCollection <WhitelistUser>(Defined.WHITELIST_TABLE_NAME).EnsureIndex(x => x.Id); GetCollection <BlacklistUser>(Defined.BLACKLIST_TABLE_NAME).EnsureIndex(x => x.Id); }