public ShardedDiscordClient (DiscordSocketConfig discordSocketConfig) { _log = LogManager.GetCurrentClassLogger(); this.discordSocketConfig = discordSocketConfig; var clientList = new List<DiscordSocketClient>(); for (int i = 0; i < discordSocketConfig.TotalShards; i++) { discordSocketConfig.ShardId = i; var client = new DiscordSocketClient(discordSocketConfig); clientList.Add(client); client.UserJoined += async arg1 => await UserJoined(arg1); client.MessageReceived += async arg1 => await MessageReceived(arg1); client.UserLeft += async arg1 => await UserLeft(arg1); client.UserUpdated += async (arg1, gu2) => await UserUpdated(arg1, gu2); client.MessageUpdated += async (arg1, m2) => await MessageUpdated(arg1, m2); client.MessageDeleted += async (arg1, arg2) => await MessageDeleted(arg1, arg2); client.UserBanned += async (arg1, arg2) => await UserBanned(arg1, arg2); client.UserPresenceUpdated += async (arg1, arg2, arg3) => await UserPresenceUpdated(arg1, arg2, arg3); client.UserVoiceStateUpdated += async (arg1, arg2, arg3) => await UserVoiceStateUpdated(arg1, arg2, arg3); client.ChannelCreated += async arg => await ChannelCreated(arg); client.ChannelDestroyed += async arg => await ChannelDestroyed(arg); client.ChannelUpdated += async (arg1, arg2) => await ChannelUpdated(arg1, arg2); _log.Info($"Shard #{i} initialized."); } Clients = clientList.AsReadOnly(); }
public async Task Start() { try { discordconfig = new DiscordSocketConfig(); discordconfig.MessageCacheSize = 10; client = new DiscordSocketClient(discordconfig); commands = new CommandService(); XmlDocument doc = new XmlDocument(); doc.Load("BotConfig.xml"); XmlNode l1 = doc.FirstChild; Activation.stats = Convert.ToBoolean(l1.SelectSingleNode("/BotConfig/Stats").InnerText); Activation.moddeletation = Convert.ToBoolean(l1.SelectSingleNode("/BotConfig/deleteConfig").InnerText); Activation.httprequest = Convert.ToBoolean(l1.SelectSingleNode("/BotConfig/httpConfig").InnerText); string token = "MzI2MDcwNzU2NTAyOTI5NDA4.DXXq2Q.y8KQEUUR_-6ZJDNv7ifUmoD2R-4"; //string token = "Mzc1Mjk3NTAzOTY2MjY1MzQ2.DQQYrQ.VF4NjvgpQCU-ksLlZF4on7zPIZg"; services = new ServiceCollection() .BuildServiceProvider(); archive = new DatabaseArchiving(); Activation.archiveobject = archive; await InstallCommands(); await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); await Task.Delay(-1); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public override void Load() { var clientConfig = new DiscordSocketConfig { AlwaysDownloadUsers = true, LogLevel = LogSeverity.Verbose, ExclusiveBulkDelete = true, MessageCacheSize = 50 }; var commandConfig = new CommandServiceConfig { CaseSensitiveCommands = false }; Bind <XyloxDiscord>().ToSelf().InSingletonScope(); Bind <Logger>().ToSelf().InSingletonScope(); Bind <CommandHandler>().ToSelf().InSingletonScope(); Bind <IXyloxConfig>().To <XyloxConfig>().InSingletonScope(); Bind <DiscordSocketClient>().ToSelf().InSingletonScope().WithConstructorArgument("config", clientConfig); Bind <CommandService>().ToSelf().InSingletonScope().WithConstructorArgument("config", commandConfig); }
private static ServiceProvider ConfigureServices(DiscordSocketConfig config) { var serviceProvider = new ServiceCollection(); serviceProvider.AddSingleton <IConfigurationService, ConfigurationService>(); serviceProvider.AddSingleton <ILoggerService, LoggerService>(); serviceProvider.AddSingleton <IMongoDBAccessService, MongoDBAccessService>(); serviceProvider.AddSingleton <IGroupHandlerService, GroupHandlerService>(); serviceProvider.AddSingleton <IRoleDispenserService, RoleDispenserService>(); serviceProvider.AddSingleton <IGuildDataExtensionsService, GuildDataExtensionsService>(); serviceProvider.AddSingleton <IUserDataService, UserDataService>(); serviceProvider.AddSingleton <IBungieService, BungieService>(); serviceProvider.AddSingleton(new DiscordSocketClient(config)); serviceProvider.AddSingleton <CommandService>(); serviceProvider.AddSingleton <CommandHandlingService>(); serviceProvider.AddSingleton <ReactionHandlingService>(); serviceProvider.AddSingleton <LockPuzzleService>(); return(serviceProvider.BuildServiceProvider()); }
async Task Initialize(BotDbContext db) { if (_initialized) { return; } StartTime = DateTime.Now; Log.Info("Initializing..."); var config = new DiscordSocketConfig(); Client = new DiscordSocketClient(config); var CommandService = new CommandService(); var map = new DependencyMap(); map.Add(this); map.Add(map); map.Add(Client); map.Add(db); map.Add(new CounterSet(new ActivatorFactory <SimpleCounter>())); map.Add(new LogSet()); map.Add(new DatabaseService(map)); map.Add(new LogService(map, ExecutionDirectory)); map.Add(new CounterService(map)); map.Add(CommandService); await CommandService.AddModulesAsync(Assembly.GetEntryAssembly()); map.Add(new BotCommandService(map)); map.Add(new TempService(map)); map.Add(new BlacklistService(map)); map.Add(new AnnounceService(map)); map.Add(new SearchService(map)); _initialized = true; }
public ShardedDiscordClient(DiscordSocketConfig discordSocketConfig) { _log = LogManager.GetCurrentClassLogger(); this.discordSocketConfig = discordSocketConfig; var clientList = new List <DiscordSocketClient>(); for (int i = 0; i < discordSocketConfig.TotalShards; i++) { discordSocketConfig.ShardId = i; var client = new DiscordSocketClient(discordSocketConfig); clientList.Add(client); client.UserJoined += arg1 => { UserJoined(arg1); return(Task.CompletedTask); }; client.MessageReceived += arg1 => { if (arg1.Author == null || arg1.Author.IsBot) { return(Task.CompletedTask); } MessageReceived(arg1); return(Task.CompletedTask); }; client.UserLeft += arg1 => { UserLeft(arg1); return(Task.CompletedTask); }; client.UserUpdated += (arg1, gu2) => { UserUpdated(arg1, gu2); return(Task.CompletedTask); }; client.MessageUpdated += (arg1, m2) => { MessageUpdated(arg1, m2); return(Task.CompletedTask); }; client.MessageDeleted += (arg1, arg2) => { MessageDeleted(arg1, arg2); return(Task.CompletedTask); }; client.UserBanned += (arg1, arg2) => { UserBanned(arg1, arg2); return(Task.CompletedTask); }; client.UserUnbanned += (arg1, arg2) => { UserUnbanned(arg1, arg2); return(Task.CompletedTask); }; client.UserPresenceUpdated += (arg1, arg2, arg3, arg4) => { UserPresenceUpdated(arg1, arg2, arg3, arg4); return(Task.CompletedTask); }; client.UserVoiceStateUpdated += (arg1, arg2, arg3) => { UserVoiceStateUpdated(arg1, arg2, arg3); return(Task.CompletedTask); }; client.ChannelCreated += arg => { ChannelCreated(arg); return(Task.CompletedTask); }; client.ChannelDestroyed += arg => { ChannelDestroyed(arg); return(Task.CompletedTask); }; client.ChannelUpdated += (arg1, arg2) => { ChannelUpdated(arg1, arg2); return(Task.CompletedTask); }; _log.Info($"Shard #{i} initialized."); } Clients = clientList.AsReadOnly(); }
/// <summary> /// Constructor of DiscordBot. /// </summary> /// <param name="token">Discord Bot auth token.</param> /// <param name="config">Special Discord.NET framework bot configuration.</param> private DiscordBot(string token, DiscordSocketConfig config) : base(config) { // Subscribe to events base.Log += Log; // Start services services = new ServiceCollection() .AddSingleton(new PhotonService( Config.Get("PHOTON_APPID"), Config.Get("GAME_VERSION") )).BuildServiceProvider(); // Automatically find and start all modules commands = new CommandService(new CommandServiceConfig() { LogLevel = LogSeverity.Info }); commands.Log += Log; commands.CommandExecuted += CommandExecuted; base.MessageReceived += TryRunCommand; commands.AddModulesAsync(Assembly.GetExecutingAssembly()).Wait(); }
public async Task MainAsync() { DiscordSocketConfig cfg = new DiscordSocketConfig(); cfg.MessageCacheSize = 100; client = new DiscordSocketClient(cfg); new CommandHandler(client); client.Log += Log; string token = "NTEyMTg5NDY5MDgwOTQ0NjUx.Ds176Q.JAtI42ov1ObKgV0vhAl1fmgcmeI"; await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); client.ReactionAdded += ReactionAdded; //client.MessageReceived += MessageReceived; await Task.Delay(-1); }
public Client(string token) { _token = token; var config = new DiscordSocketConfig { AlwaysDownloadUsers = true, }; _client = new DiscordSocketClient(config); #if DEBUG _client.Log += LogAsync; #endif _commands = new CommandService(); _services = new ServiceCollection() .AddSingleton(_client) .AddSingleton(_commands) .AddSingleton(new PasteBinFetcher()) .AddSingleton(new Parser()) .BuildServiceProvider(); _rmtScanner = new RmtScanner(); }
public async Task ConnectAsync(string _Token) { await ControlHandler.LogAsync("Connecting..."); this.Token = _Token; DiscordSocketConfig _config = new DiscordSocketConfig { MessageCacheSize = 128, }; Client = new DiscordSocketClient(_config); Commands = new CommandService(new CommandServiceConfig() { DefaultRunMode = RunMode.Async }); Services = new ServiceCollection() .AddSingleton(Client) .AddSingleton(Commands) .BuildServiceProvider(); await InstallCommandsAsync(); Client.UserJoined += Global.GuildEventHandler.GreetNewUser; Client.ChannelCreated += Global.GuildEventHandler.ChannelUpdate; Client.ChannelDestroyed += Global.GuildEventHandler.ChannelUpdate; Client.ChannelUpdated += Global.GuildEventHandler.ChannelModified; Client.Ready += Global.GuildEventHandler.ClientReady; Client.MessageReceived += Global.GuildEventHandler.MessageReceived; Client.Log += Global.GuildEventHandler.Log; Client.GuildUpdated += Global.GuildEventHandler.GuildModifed; Client.JoinedGuild += Global.GuildEventHandler.GuildJoinLeave; Client.LeftGuild += Global.GuildEventHandler.GuildJoinLeave; await Client.LoginAsync(TokenType.Bot, Token); await Client.StartAsync(); }
public async Task MainAsync() { var config = new DiscordSocketConfig { AlwaysDownloadUsers = true, MessageCacheSize = 120 }; _client = new DiscordSocketClient(config); _client.Log += Log; _client.MessageReceived += MessageReceivedAsync; await _client.LoginAsync(TokenType.Bot, HiddenInfo.token); await _client.StartAsync(); CommandService service = new CommandService(); CommandHandler handler = new CommandHandler(_client, service); Logging logger = new Logging(_client); await _client.SetGameAsync("version 0.4.2"); await handler.InstallCommandsAsync(); logger.SetUp(); await Log(new LogMessage(LogSeverity.Info, "Main", "Setup complete")); //Console.WriteLine(DateTime.Now.TimeOfDay + " All classes created"); if (!Directory.Exists("/home/bob_the_daniel/Data")) { Console.WriteLine(DateTime.Now.TimeOfDay + " No data folder"); } // Block this task until the program is closed. await Task.Delay(-1); await _client.SetGameAsync("shutting down"); }
public async Task RunBotAsync() { Console.WriteLine("b1g, un bot de Discord pendejo | developed by Muphy"); var _config = new DiscordSocketConfig { MessageCacheSize = 1000 }; _client = new DiscordSocketClient(_config); _commands = new CommandService(); _services = new ServiceCollection() .AddSingleton(_client) .AddSingleton(_commands) .AddSingleton <LavaRestClient>() .AddSingleton <LavaSocketClient>() .AddSingleton <MusicService>() .BuildServiceProvider(); string botToken = "NjEwNTc4MDQwNjc3NzI4MjY2.XVHTNw.NcJpvOTzcvUAzW97juxU0LJdC-A"; _client.Log += Log; _client.UserJoined += WooUserJoined; _client.MessageUpdated += WooMessageUpdated; _client.MessageDeleted += WooMessageDeleted; _client.ReactionAdded += WooReactionAdded; _client.ReactionRemoved += WooReactionRemoved; _client.MessageReceived += WooMessageReceived; await _services.GetRequiredService <MusicService>().InitializeAsync(); await RegisterCommandAsync(); await _client.LoginAsync(TokenType.Bot, botToken); await _client.StartAsync(); await Task.Delay(-1); }
private ServiceProvider ConfigureServices() { var dbPass = Environment.GetEnvironmentVariable(Config.DB_PASSWORD_ENV_VAR); var dbUser = Environment.GetEnvironmentVariable(Config.DB_USER_ENV_VAR); if (string.IsNullOrEmpty(dbUser)) { dbUser = "******"; } var discordSocketConfig = new DiscordSocketConfig(); discordSocketConfig.AlwaysDownloadUsers = true; var discordClient = new DiscordSocketClient(discordSocketConfig); return(new ServiceCollection() .AddDbContextPool <CircusDbContext>( dbContextOptions => dbContextOptions .UseMySql( $"server=localhost;user={dbUser};password={dbPass};database=circusdb;charset=utf8mb4", mySqlOptions => mySqlOptions .ServerVersion(new Version(10, 3, 27), ServerType.MariaDb) .CharSetBehavior(CharSetBehavior.NeverAppend)) .UseLoggerFactory( LoggerFactory.Create(logging => logging .AddConsole() .AddFilter(level => level >= LogLevel.Information))) .EnableSensitiveDataLogging() .EnableDetailedErrors()) .AddSingleton <DiscordSocketClient>(discordClient) .AddSingleton <CommandService>() .AddSingleton <CommandHandler>() .AddSingleton <Logger>() .AddSingleton <ReactionHandler>() .AddSingleton <MessageModificationHandler>() .BuildServiceProvider()); }
public async Task MainAsync() { // You specify the amount of shards you'd like to have with the // DiscordSocketConfig. Generally, it's recommended to // have 1 shard per 1500-2000 guilds your bot is in. var config = new DiscordSocketConfig { TotalShards = 2 }; // You should dispose a service provider created using ASP.NET // when you are finished using it, at the end of your app's lifetime. // If you use another dependency injection framework, you should inspect // its documentation for the best way to do this. using (var services = ConfigureServices(config)) { var client = services.GetRequiredService <DiscordShardedClient>(); // The Sharded Client does not have a Ready event. // The ShardReady event is used instead, allowing for individual // control per shard. client.ShardReady += ReadyAsync; client.Log += LogAsync; await services.GetRequiredService <InteractionHandlingService>() .InitializeAsync(); await services.GetRequiredService <CommandHandlingService>() .InitializeAsync(); // Tokens should be considered secret data, and never hard-coded. await client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("token")); await client.StartAsync(); await Task.Delay(Timeout.Infinite); } }
async Task Execute() { Console.WriteLine("Starting Note to Self Bot v1.1 ..."); MasterConfig Config = MasterConfig.Load(); if (Config == null) { Config = MasterConfig.Setup(); } Config.Save(); Notes = new NotesManager(Config.MongoUser, Config.MongoPass); DiscordSocketConfig ClientConfig = new DiscordSocketConfig() { DefaultRetryMode = RetryMode.AlwaysFail, LogLevel = LogSeverity.Info }; CommandServiceConfig CommandConfig = new CommandServiceConfig() { DefaultRunMode = RunMode.Async }; Client = new DiscordShardedClient(ClientConfig); Command = new CommandService(CommandConfig); await InitializeCommands(); Client.Log += (msg) => Log(msg); await Client.LoginAsync(TokenType.Bot, Config.Token); await Client.StartAsync(); await Task.Delay(-1); }
public async Task RunBotASync() { _configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", false) .Build(); var config = new DiscordSocketConfig { MessageCacheSize = 100, LogLevel = LogSeverity.Verbose }; _client = new DiscordSocketClient(config); _commands = new CommandService(); _reactions = new ReactionService(); _services = new ServiceCollection() .AddSingleton(_client) .AddSingleton(_commands) .AddSingleton(_reactions) .AddSingleton(_configuration) .AddLogging(builder => builder.AddSerilog(dispose: true)) .AddEntityFrameworkSqlServer() .AddDbContext <GameBotDbContext>(options => options.UseNpgsql(_configuration.GetConnectionString("GameBotDb"))) .BuildServiceProvider(); var token = _configuration.GetSection("DiscordToken").Value; _client.Log += _client_Log; await RegisterCommandsAsync(); await _client.LoginAsync(TokenType.Bot, token); await _client.StartAsync(); await Task.Delay(-1); }
public static async Task Main(string[] args) { GlobalEvents.PrintStartupMessage(); GlobalConfiguration.LoadConfiguration(); _services = ConfigureServices(new ServiceCollection()); _logger = _services.GetRequiredService <ILogger <Program> >(); _joinService = _services.GetRequiredService <IJoinService>(); _discordConfig = new DiscordSocketConfig() { LargeThreshold = 250, AlwaysDownloadUsers = true, // RIP memory 2018 DefaultRetryMode = RetryMode.AlwaysRetry }; _commandServiceConfig = new CommandServiceConfig() { ThrowOnError = true, // haha who cares about debugging just let it fly CaseSensitiveCommands = false }; _client = new DiscordSocketClient(_discordConfig); _commandService = new CommandService(_commandServiceConfig); _client.UserJoined += HandleUserJoinAsync; _client.MessageReceived += HandleCommandAsync; await _commandService.AddModulesAsync(Assembly.GetEntryAssembly()); _logger.LogDebug("Haruna has been loaded with all modules and commands."); await _client.LoginAsync(TokenType.Bot, GlobalConfiguration.BotToken, validateToken : true); await _client.StartAsync(); await HandlePlayingTagsAsync(); _logger.LogInformation("Haruna has started and is running."); await Task.Delay(-1); }
public static async Task ConnectAsync() { _DiscordConfig = new DiscordSocketConfig { DefaultRetryMode = RetryMode.AlwaysRetry, ExclusiveBulkDelete = true, MessageCacheSize = 100, AlwaysDownloadUsers = true, LogLevel = LogSeverity.Info }; _DiscordClient = new DiscordSocketClient(_DiscordConfig); _DiscordClient.Log += Log; _MentionProvider = new ServiceCollection().AddSingleton(_DiscordClient) .AddSingleton(_MentionService) .AddSingleton <MentionCommands>() .BuildServiceProvider(); _MentionProvider.GetRequiredService <CommandService>().Log += Log; _MentionService.Log += Log; _DiscordClient.Connected += Connected; _DiscordClient.JoinedGuild += JoinedGuild; _DiscordClient.GuildAvailable += GuildAvailable; _DiscordClient.GuildMembersDownloaded += GuildMembersDownloaded; _DiscordClient.MessageReceived += MessageReceived; await _MentionProvider.GetRequiredService <MentionCommands>().InitializeAsync(); try { await _DiscordClient.LoginAsync(TokenType.Bot, SettingsManager.Configuration.DiscordToken); await _DiscordClient.StartAsync(); } catch (Exception ex) { LoggingManager.Log.Fatal(ex); Environment.Exit(1); } }
public async Task MainAsync() { DiscordSocketConfig config = new DiscordSocketConfig(); config.WebSocketProvider = WS4NetProvider.Instance; config.AlwaysDownloadUsers = true; config.MessageCacheSize = 1000; //TODO: Set Correct DateTimeOffset. client = new DiscordSocketClient(config); client.Log += Log; client.MessageReceived += Client_MessageReceived; client.MessageUpdated += Client_MessageUpdated; client.MessageDeleted += Client_MessageDeleted; commands = new CommandService(); services = new ServiceCollection() .BuildServiceProvider(); await InstallCommands(); await Modules.Quotation.QuoteModule.Start(client); await Modules.Help.HelpCommandsModule.Start(commands); if (!File.Exists(TokenFile)) { Console.WriteLine("No Token.txt found"); return; } string token = File.ReadAllText(TokenFile); await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); // Block this task until the program is closed. await Task.Delay(-1); }
public async Task MainAsync(string[] args) { System.Console.WriteLine("Starting PokeBot Version v0.2"); DiscordSocketConfig discordConfig = new DiscordSocketConfig { MessageCacheSize = 10 }; _client = new DiscordSocketClient(discordConfig); _config = BuildConfig(); var services = ConfigureServices(); using (var scope = services.CreateScope()) { var serviceProvider = scope.ServiceProvider; try { var context = serviceProvider.GetRequiredService <DataContext>(); context.Database.Migrate(); await context.SaveChangesAsync(); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } services.GetRequiredService <LogService>(); services.GetRequiredService <PokemonHandlingService>().Initialize(services); services.GetRequiredService <PokeBattleHandlingService>().Initialize(services); await services.GetRequiredService <CommandHandlingService>().InitializeAsync(services); await _client.LoginAsync(TokenType.Bot, _config.GetSection("AppSettings:Token").Value); await _client.StartAsync(); await Task.Delay(-1); }
public async Task MainAsync() { Console.OutputEncoding = Encoding.UTF8; var config = new DiscordSocketConfig { MessageCacheSize = 100 }; var client = new DiscordSocketClient(config); string discordToken; string authSecret; string basePath; StreamReader file = new StreamReader(@"tokens.txt"); discordToken = file.ReadLine(); authSecret = file.ReadLine(); basePath = file.ReadLine(); firebaseConfig = new FirebaseConfig { AuthSecret = authSecret, BasePath = basePath, }; //firebaseClient = new FireSharp.FirebaseClient(firebaseConfig); firebase.initFirebase(authSecret, basePath); await client.LoginAsync(TokenType.Bot, discordToken); await client.StartAsync(); //client.Log += Log; client.MessageReceived += MessageReceived; client.MessageUpdated += MessageUpdated; client.MessageDeleted += MessageDeleted; client.UserVoiceStateUpdated += UserVoiceStateUpdated; await Task.Delay(-1); }
private void ConfigureServices(IServiceCollection services) { var config = new DiscordSocketConfig(); Configuration.Bind("DiscordSocketConfig", config); services .AddSingleton(Configuration) .AddLogging() .AddDbContext <IntroContext>(opt => opt.UseLazyLoadingProxies().UseSqlServer(Configuration.GetConnectionString("SQL"))) .AddSingleton(new DiscordShardedClient(config)) .AddLavaNode(x => { x.SelfDeaf = false; x.Authorization = "youshallnotpass"; x.Hostname = "localhost"; x.Port = 2333; }) .AddSingleton <StartupService>() .AddSingleton <CommandService>() .AddSingleton <AudioService>() .AddSingleton <CommandHandlingService>(); }
public Assistant(AssistantConfig config) { DiscordSocketConfig clientConfig = new DiscordSocketConfig { LogLevel = config.Log?.Severity ?? LoggingService.DefaultSeverity }; _config = config; _client = new DiscordSocketClient(); _services = new ServiceCollection() .AddSingleton(_config) .AddSingleton(_client) .AddSingleton(new CommandService(new CommandServiceConfig { DefaultRunMode = RunMode.Async })) .AddSingleton <Random>() .AddSingleton <HttpService>() .AddSingleton <CommandHandler>() .AddSingleton <LoggingService>() .AddSingleton <IInitializable>(s => s.GetRequiredService <CommandHandler>()) .AddSingleton <IInitializable>(s => s.GetRequiredService <LoggingService>()) .BuildServiceProvider(); }
public async Task StartupAsync() { var config = new DiscordSocketConfig { ExclusiveBulkDelete = true }; _client = new DiscordSocketClient(config); _commandService = new CommandService(); _commandHandler = new CommandHandler(_client, _commandService); _client.Log += LogEvent.Event; _client.Connected += ConnectedEvent.Event; await _commandHandler.InstallCommandsASync(); await _client.LoginAsync(TokenType.Bot, _configuration["discord_token"]); await _client.StartAsync(); await _client.SetGameAsync("Created by Ayresia#2327", null, ActivityType.Playing); await Task.Delay(-1); }
public async Task Start() { // Enables retrieving "invisible" users' details var config = new DiscordSocketConfig { AlwaysDownloadUsers = true }; _client = new DiscordSocketClient(config); _commands = new CommandService(); _services = new ServiceCollection().BuildServiceProvider(); await InstallCommands(_services).ConfigureAwait(false); await _client.LoginAsync(TokenType.Bot, _botToken).ConfigureAwait(false); await _client.SetStatusAsync(UserStatus.Online).ConfigureAwait(false); await _client.StartAsync().ConfigureAwait(false); _client.Log += _client_Log; }
internal AdaClient() { L.W("ADA DSC", "Initializing Discord"); this.Game = "Banhammer 40,000"; var spr = AdaBotCore.SocketManager.SocketProvider; var spv = spr != null ? spr.Provider : null; var dsc = new DiscordSocketConfig() { LogLevel = Debugger.IsAttached ? LogSeverity.Debug : LogSeverity.Info, AudioMode = AudioMode.Disabled, WebSocketProvider = spv }; this.DiscordClient = new DiscordSocketClient(dsc); this.DiscordClient.Log += Client_Log; this.DiscordClient.Ready += Client_Ready; // modlog events this.DiscordClient.UserJoined += DiscordClient_UserJoined; this.DiscordClient.UserLeft += DiscordClient_UserLeft; this.DiscordClient.UserBanned += DiscordClient_UserBanned; this.DiscordClient.UserUnbanned += DiscordClient_UserUnbanned; var a = typeof(AdaClient).GetTypeInfo().Assembly; var n = a.GetName(); var l = Path.GetDirectoryName(a.Location); L.W("ADA DSC", "Loading config"); var sp = Path.Combine(l, "config.json"); var sjson = File.ReadAllText(sp, AdaBotCore.UTF8); var sjo = JObject.Parse(sjson); this.ConfigJson = sjo; this.Token = (string)sjo["token"]; L.W("ADA DSC", "Discord initialized"); }
public async Task MainAsync() { var tcp = new TcpListener(new IPAddress(new byte[] { 0, 0, 0, 0 }), int.Parse(Environment.GetEnvironmentVariable("PORT"))); tcp.Start(); var _config = new DiscordSocketConfig { ExclusiveBulkDelete = true, LogLevel = LogSeverity.Info, MessageCacheSize = 10, }; _client = new DiscordSocketClient(_config); var service = BuildServiceProvider(); _client.Log += service.GetService <LogService>().Log; try { await _client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("DiscordToken")); await _client.StartAsync(); await service.GetRequiredService <CommandHandler>().InstallCommandsAsync(); _client.UserJoined += service.GetRequiredService <UserJoinedEvent>().OnUserJoin; _client.ReactionAdded += service.GetRequiredService <UserReactedEvent>().OnReaction; } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { await Task.Delay(-1); } }
public Cirilla(LogSeverity logSeverity) { var config = new DiscordSocketConfig { LogLevel = logSeverity }; if (Information.NeedsWs4Net) { config.WebSocketProvider = WS4NetProvider.Instance; } Client = new DiscordSocketClient(config); Client.Log += Log; Client.MessageReceived += MessageReceived; Client.MessageReceived += EventHelper.RandomEmoji; //Client.MessageReceived += EventHelper.QuestionThinking; annoying? Client.UserJoined += EventHelper.UserJoined; Client.UserLeft += EventHelper.UserLeft; Client.LeftGuild += EventHelper.LeftGuild; Client.JoinedGuild += EventHelper.JoinedGuild; Client.GuildAvailable += EventHelper.GuildAvailable; Client.Ready += EventHelper.Ready; var serviceConfig = new CommandServiceConfig { CaseSensitiveCommands = false, LogLevel = logSeverity }; Service = new CommandService(serviceConfig); Service.Log += Log; Service.AddTypeReader(typeof(Timediff), new ReminderTypeReader()); Service.AddModulesAsync(Assembly.GetEntryAssembly()).GetAwaiter().GetResult(); Login().GetAwaiter().GetResult(); }
private async Task StartAsync() { clientConfig = new DiscordSocketConfig() { DefaultRetryMode = RetryMode.AlwaysRetry, LogLevel = LogSeverity.Info }; Client = new DiscordSocketClient(clientConfig); Client.Log += Logger; await Client.LoginAsync(TokenType.Bot, Properties.Settings.Default.DiscordToken); await Client.StartAsync(); Client.Ready += async() => { Console.WriteLine("Tsukihi has now connected to:"); Console.WriteLine(string.Join(", ", Client.Guilds)); Commands = new Commands(); await Commands.Install(); // Bot status ? ? }; Client.Disconnected += async(_) => // Currently just restarts entire client on disconnect - problematic { Process.Start(new ProcessStartInfo() { FileName = Directory.GetCurrentDirectory() + "\\Tsukihi.exe" }); Environment.Exit(0); }; await Task.Delay(-1); }
private DiscordSocketConfig BuildClientConfig() { string logLevel = _config["log_level"]; DiscordSocketConfig clientConfig = new DiscordSocketConfig(); switch (logLevel) { case "Critical": clientConfig.LogLevel = LogSeverity.Critical; break; case "Debug": clientConfig.LogLevel = LogSeverity.Debug; break; case "Error": clientConfig.LogLevel = LogSeverity.Error; break; case "Info": clientConfig.LogLevel = LogSeverity.Info; break; case "Verbose": clientConfig.LogLevel = LogSeverity.Verbose; break; case "Warning": clientConfig.LogLevel = LogSeverity.Warning; break; default: clientConfig.LogLevel = LogSeverity.Info; break; } return(clientConfig); }
private DiscordSocketConfig InitDiscordSocketConfig() { DiscordSocketConfig discordSocketConfig = new DiscordSocketConfig(); string value = _config.GetValue(ConfigKeys.LogSeverity); switch (value) { case "Critical": discordSocketConfig.LogLevel = LogSeverity.Critical; break; case "Debug": discordSocketConfig.LogLevel = LogSeverity.Debug; break; case "Error": discordSocketConfig.LogLevel = LogSeverity.Error; break; case "Info": discordSocketConfig.LogLevel = LogSeverity.Info; break; case "Verbose": discordSocketConfig.LogLevel = LogSeverity.Verbose; break; case "Warning": discordSocketConfig.LogLevel = LogSeverity.Warning; break; default: discordSocketConfig.LogLevel = LogSeverity.Info; break; } return(discordSocketConfig); }