Example #1
0
        }                                                                  // not yet set for now

        public async Task RunAsync(string token)
        {
            var config = new DiscordConfiguration
            {
                Token           = token,
                TokenType       = TokenType.Bot,
                AutoReconnect   = true,
                MinimumLogLevel = LogLevel.Debug
            };

            _Client = new DiscordClient(config);
            // every client ready, guild available and client error
            _Client.Ready          += Client_OnReady;
            _Client.GuildAvailable += Client_GuildConnected;
            _Client.ClientErrored  += Client_ClientError;


            SharedData.prefixes.Add("i!"); //default prefix
            //might wanna add a interactivity here along with its config
            var commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes      = SharedData.prefixes, // for now it is default prefix can turn this to a list
                EnableDms           = true,                // so botDev can set himself as dev lmao
                EnableMentionPrefix = false,
                EnableDefaultHelp   = true,
                DmHelp = false
            };

            _Commands = _Client.UseCommandsNext(commandsConfig);
            _Commands.CommandExecuted += Command_CommandExecuted;
            _Commands.CommandErrored  += Command_CommandError;


            _Commands.RegisterCommands <IamagesCmds>();
            _Commands.RegisterCommands <UtilCmds>();
            _Commands.SetHelpFormatter <HelpFormatter>();

            var emojis = new PaginationEmojis() //emojis to be used in the pagination
            {
                Left      = DiscordEmoji.FromName(_Client, ":arrow_backward:"),
                Right     = DiscordEmoji.FromName(_Client, ":arrow_forward:"),
                SkipLeft  = null,
                SkipRight = null
            };

            _Interactivity = _Client.UseInteractivity(new InteractivityConfiguration
            {
                PaginationBehaviour = DSharpPlus.Interactivity.Enums.PaginationBehaviour.WrapAround,
                PaginationEmojis    = emojis,
                Timeout             = TimeSpan.FromSeconds(60) //increase timeout
            });

            SharedData.reportChannel = await _Client.GetChannelAsync(SharedData.reportChannelid);

            SharedData.startTime = DateTime.Now;
            //client connection to bot application on the discord api
            await _Client.ConnectAsync();

            await Task.Delay(-1); // <------ needs to re looked upon
        }
Example #2
0
        public async Task RunAsync()
        {
            var json = string.Empty;

            using (var fs = File.OpenRead("config.json"))
                using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                    json = await sr.ReadToEndAsync().ConfigureAwait(false);

            var ConfigJson = JsonConvert.DeserializeObject <ConfigJson>(json);

            var config = new DiscordConfiguration
            {
                Token           = ConfigJson.Token,
                TokenType       = TokenType.Bot,
                AutoReconnect   = true,
                MinimumLogLevel = LogLevel.Debug
            };

            var commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes      = new string[] { ConfigJson.Prefix },
                EnableMentionPrefix = false
            };

            Client   = new DiscordClient(config);
            Commands = Client.UseCommandsNext(commandsConfig);

            Commands.RegisterCommands <GeneralCommands>();

            Client.Ready += Client_Ready;

            await Client.ConnectAsync();

            await Task.Delay(-1);
        }
Example #3
0
        public async Task RunAsync()
        {
            var config = new DiscordConfiguration()
            {
                Token                 = Constants.API_TOKEN,
                TokenType             = TokenType.Bot,
                AutoReconnect         = true,
                LogLevel              = LogLevel.Debug,
                UseInternalLogHandler = true,
            };

            Client = new DiscordClient(config);

            Client.Ready += OnClientReady;

            var commandConfig = new CommandsNextConfiguration()
            {
                StringPrefix        = Constants.PREFIX,
                EnableMentionPrefix = true,
                EnableDms           = false,
                CaseSensitive       = false,
            };

            Commands = Client.UseCommandsNext(commandConfig);

            Commands.RegisterCommands <SlothCommands>();

            await Client.ConnectAsync();

            await Task.Delay(-1);
        }
Example #4
0
 public Config(ILogger logger, DiscordConfiguration discordConfiguration, CommandsNextConfiguration commandsNextConfiguration, TriviaStoreSettings triviaStoreSettings)
 {
     Logger = logger;
     DiscordConfiguration      = discordConfiguration;
     CommandsNextConfiguration = commandsNextConfiguration;
     TriviaStoreSettings       = triviaStoreSettings;
 }
        public DiscordBotService(
            ILoggerFactory loggerFactory,
            IOptions <BotConfiguration> config,
            IServiceProvider services)
        {
            var dcfg = new DiscordConfiguration
            {
                Token     = config.Value.Token,
                TokenType = TokenType.Bot,

                LoggerFactory   = loggerFactory,
                MinimumLogLevel = LogLevel.Information
            };

            this.Discord = new DiscordClient(dcfg);

            this.CommandsNext = this.Discord.UseCommandsNext(new CommandsNextConfiguration
            {
                StringPrefixes      = new[] { config.Value.Prefix },
                CaseSensitive       = false,
                EnableMentionPrefix = true,
                Services            = services
            });

            this.CommandsNext.RegisterCommands <AdminCommandModule>();
            this.CommandsNext.RegisterCommands <GameCommandModule>();

            this.CommandsNext.CommandErrored += this.CommandsNext_CommandErrored;

            this.Logger = loggerFactory.CreateLogger <DiscordBotService>();
            this.Logger.LogInformation("Discord client created");
        }
Example #6
0
        public DiscordBot(ClientConfiguration clientConfig)
        {
            BotAdmins  = clientConfig.BotAdmins;
            LogChannel = clientConfig.LogChannel;
#if DEBUG
            Token = clientConfig.TestToken;
#else
            Token = clientConfig.Token;
#endif
            var config = new DiscordConfiguration()
            {
                Token     = Token,
                TokenType = TokenType.Bot
            };

            GuildPrefixes = new ConcurrentDictionary <ulong, string>();

            Client = new DiscordClient(config);

            Commands = Client.UseCommandsNext(new CommandsNextConfiguration()
            {
                PrefixResolver = x => ResolvePrefix(x)
            });

            Commands.CommandErrored += Commands_CommandErrored;
        }
Example #7
0
        public async Task RunBotAsync()
        {
            string json = "";

            using (FileStream fs = File.OpenRead("config.json"))
            {
                using StreamReader sr = new StreamReader(fs, new UTF8Encoding(false));
                json = await sr.ReadToEndAsync();
            }

            ConfigJson           cfgjson = JsonConvert.DeserializeObject <ConfigJson>(json);
            DiscordConfiguration cfg     = new DiscordConfiguration
            {
                Token     = cfgjson.Token,
                TokenType = TokenType.Bot,

                AutoReconnect         = true,
                LogLevel              = LogLevel.Debug,
                UseInternalLogHandler = true
            };

            Client = new DiscordClient(cfg);
            Client.UseVoiceNext();
            Client.UseCommandsNext(new CommandsNextConfiguration
            {
                StringPrefixes = new[] { cfgjson.CommandPrefix },
                EnableDms      = false
            }).RegisterCommands <Commands>();
            Client.Ready          += Client_Ready;
            Client.GuildAvailable += Client_GuildAvailable;
            Client.ClientErrored  += Client_ClientError;
            await Client.ConnectAsync();

            await Task.Delay(-1);
        }
Example #8
0
        public async Task RunAsnyc()
        {
            var json = string.Empty;

            using (var fs = File.OpenRead("config.json"))
                using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                    json = await sr.ReadToEndAsync().ConfigureAwait(false);

            var configJson = JsonConvert.DeserializeObject <ConfigJson>(json);
            var config     = new DiscordConfiguration
            {
                Token         = configJson.Token,
                TokenType     = TokenType.Bot,
                AutoReconnect = true
            };

            client = new DiscordClient(config);


            var commandConfig = new CommandsNextConfiguration
            {
                StringPrefixes      = new String[] { configJson.Prefix },
                EnableMentionPrefix = true,
                EnableDms           = false,
                DmHelp = true,
                IgnoreExtraArguments = true
            };

            Commands = client.UseCommandsNext(commandConfig);
            Commands.RegisterCommands <RollCommand>();

            await client.ConnectAsync();

            await Task.Delay(-1);
        }
Example #9
0
        private static async Task MainTask()
        {
            // First we'll want to initialize our DiscordClient..
            var cfg = new DiscordConfiguration()
            {
                AutoReconnect  = true,                                            // Whether you want DSharpPlus to automatically reconnect
                LargeThreshold =
                    250,                                                          // Total number of members where the gateway will stop sending offline members in the guild member list
                LogLevel               = LogLevel.Debug,                          // Minimum log level you want to use
                Token                  = File.ReadAllText("../token.txt").Trim(), // Your token
                TokenType              = TokenType.Bot,                           // Your token type. Most likely "Bot"
                UseInternalLogHandler  = true,                                    // Whether you want to use the internal log handler
                WebSocketClientFactory = WebSocket4NetCoreClient.CreateNew
            };
            var client = new DiscordClient(cfg);

            // Now we'll want to define our events
            client.DebugLogger.LogMessage(LogLevel.Info, "Bot", "Initializing events", DateTime.Now);

            // First off, the MessageCreated event.
            client.DebugLogger.LogMessage(LogLevel.Info, "Bot", "Initializing MessageCreated", DateTime.Now);

            client.MessageCreated += MessageCreated;

            await client.ConnectAsync();

            client.DebugLogger.LogMessage(LogLevel.Info, "Bot", "Connected", DateTime.Now);

            await Task.Delay(-1);
        }
Example #10
0
        public static void InitializeBot(Config config)
        {
            var clientConfiguration = new DiscordConfiguration
            {
                Token     = config.GetToken(),
                TokenType = TokenType.Bot,

                AutoReconnect   = true,
                Intents         = DiscordIntents.AllUnprivileged,
                MinimumLogLevel = LogLevel.Information,
            };

            var commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes      = config.GetCommandPrefix(),
                EnableDms           = true,
                EnableMentionPrefix = true,
            };

            var interactivityConfig = new InteractivityConfiguration
            {
                PollBehaviour = PollBehaviour.KeepEmojis,
                Timeout       = TimeSpan.FromSeconds(30),
            };

            Client = new DiscordClient(clientConfiguration);
            Client.UseInteractivity(interactivityConfig);
            _commands = Client.UseCommandsNext(commandsConfig);

            _commands.RegisterCommands <RoleBotCommandModule>();

            DbAccess = new DataAccessHelper("database.db");
        }
Example #11
0
        private DiscordClient CreateClient(Configuration config)
        {
            try {
                var discordConfig = new DiscordConfiguration {
                    Token           = config.Token,
                    TokenType       = TokenType.Bot,
                    AutoReconnect   = true,
                    MinimumLogLevel = LogLevel.Information
                };

                var client = new DiscordClient(discordConfig);
                client.Ready += OnReadyAsync;

                var commandsConfig = new CommandsNextConfiguration {
                    StringPrefixes      = new[] { config.Prefix },
                    EnableMentionPrefix = false,
                    EnableDms           = true,
                    CaseSensitive       = false,
                    DmHelp = true
                };

                var commands = client.UseCommandsNext(commandsConfig);

                client.UseInteractivity(new InteractivityConfiguration {
                    Timeout = TimeSpan.FromMinutes(30)
                });

                return(client);
            }
            catch (Exception exc) {
                Console.WriteLine(exc.Demystify());
                throw;
            }
        }
        public override async Task <bool> ExecuteCheckAsync(CommandContext ctx, bool help)
        {
            DiscordUser owner = ctx.Client.CurrentApplication.Owner;

            if (IsTeamUser(owner))
            {
                using (var httpClient = new HttpClient())
                {
                    DiscordConfiguration configuration = GetDiscordConfiguration(ctx.Client);
                    string token = GetToken(configuration);
                    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", token);
                    var response = await httpClient.GetAsync($"https://discordapp.com/api/teams/{owner.Id}/members");


                    string json = await response.Content.ReadAsStringAsync();

                    var jArray = (JArray)JsonConvert.DeserializeObject(json);
                    foreach (JToken item in jArray)
                    {
                        ulong id = (ulong)item["user"]["id"];
                        if (id == ctx.User.Id)
                        {
                            return(true);
                        }
                    }
                    return(false);
                }
            }
            else
            {
                return(owner.Id == ctx.User.Id);
            }
        }
Example #13
0
        public BotAmongUs(JsonConfiguration configuration)
        {
            _Configuration = configuration;
            var config = new DiscordConfiguration
            {
                Token           = _Configuration.Token,
                TokenType       = TokenType.Bot,
                AutoReconnect   = true,
                MinimumLogLevel = LogLevel.Debug
            };

            _Client = new DiscordClient(config);

            var commands = new CommandsNextConfiguration
            {
                StringPrefixes = new List <string> {
                    _Configuration.Prefix
                },
                EnableDms = false,
                Services  = GetServiceProvider()
            };

            _CommandsExtension = _Client.UseCommandsNext(commands);
            _CommandsExtension.RegisterCommands <TextCommands>();

            var interactivityConfiguration = new InteractivityConfiguration
            {
                Timeout = TimeSpan.FromMinutes(5)
            };

            _Client.UseInteractivity(interactivityConfiguration);
            _Client.Ready          += OnClientIsReady;
            _Client.GuildAvailable += OnGuildAvailable;
        }
Example #14
0
        //constructor
        public Bot(IServiceProvider services)
        {
            //creates the string to hold the config file
            string json = string.Empty;

            //reads the config file
            using (FileStream fs = File.OpenRead("config.json"))
                using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))
                    json = sr.ReadToEnd();

            //deserializes the json into a struct
            ConfigJson configJson = JsonConvert.DeserializeObject <ConfigJson>(json);

            //configures up the bot's settings
            DiscordConfiguration config = new DiscordConfiguration
            {
                Token                 = configJson.Token,
                TokenType             = TokenType.Bot,
                AutoReconnect         = true,
                LogLevel              = LogLevel.Debug,
                UseInternalLogHandler = true
            };

            //initializes the client
            Client = new DiscordClient(config);

            //readies the bot
            Client.Ready += OnClientReady;

            //configures the interactivity settings
            Client.UseInteractivity(new InteractivityConfiguration
            {
                PollBehaviour = DSharpPlus.Interactivity.Enums.PollBehaviour.KeepEmojis
            });

            //configures the command settings
            CommandsNextConfiguration commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes      = new string[] { configJson.Prefix },
                EnableDms           = false,
                EnableMentionPrefix = true,
                DmHelp   = true,
                Services = services
            };

            //activates commands
            Commands = Client.UseCommandsNext(commandsConfig);

            //register all commands for the bot
            Commands.RegisterCommands <FunCommands>();
            Commands.RegisterCommands <LinkCommands>();
            Commands.RegisterCommands <RoleCommands>();
            Commands.RegisterCommands <PollCommand>();
            Commands.RegisterCommands <TestCommands>();
            Commands.RegisterCommands <ItemCommands>();
            Commands.RegisterCommands <ProfileCommands>();

            //connects to the server
            Client.ConnectAsync();
        }
Example #15
0
        public async Task RunAsync()
        {
            var config = new DiscordConfiguration
            {
                Token           = "<Discord Bot Token>",
                TokenType       = TokenType.Bot,
                AutoReconnect   = true,
                MinimumLogLevel = LogLevel.Debug
            };

            var commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes       = new [] { "." },
                EnableMentionPrefix  = true,
                EnableDms            = true,
                CaseSensitive        = false,
                IgnoreExtraArguments = true
            };


            Client        = new DiscordClient(config);
            Client.Ready += Client_Ready;
            Commands      = Client.UseCommandsNext(commandsConfig);
            Commands.RegisterCommands <Commands>();
            await Client.ConnectAsync();

            await Task.Delay(-1);

            System.Timers.Timer timer = new System.Timers.Timer {
                Interval = 600
            };
            timer.Elapsed += Timer_Elapsed;
            timer.Start();
        }
Example #16
0
        public DiscordBot(ILogger <DiscordBot> logger)
        {
            _logger = logger;
            _logger.LogWarning("Creating DiscordBot");


            var botToken = Environment.GetEnvironmentVariable("TEAMO_BOT_TOKEN");

            if (botToken is null)
            {
                _logger.LogError("No bot token specified! Set the TEAMO_BOT_TOKEN environment to allow connecting the bot.");
                Environment.Exit(-1);
            }

            var config = new DiscordConfiguration
            {
                Token = Environment.GetEnvironmentVariable("TEAMO_BOT_TOKEN"),
                UseInternalLogHandler = false
            };

            Client = new DiscordClient(config);

            Client.Ready += OnClientReady;
            Client.DebugLogger.LogMessageReceived += _logger.LogDSharp;

            Client.MessageCreated += async e =>
            {
                _logger.LogInformation("A new message was created!");
                if (e.Message.Content.ToLower(CultureInfo.CurrentCulture).StartsWith("ping", StringComparison.Ordinal))
                {
                    await e.Message.RespondAsync("pong!").ConfigureAwait(false);
                }
            };
        }
Example #17
0
        public Bot(BotConfig botConfig, DBConfig dBConfig)
        {
            DiscordConfiguration discordConfiguration = new DiscordConfiguration
            {
                Token                 = botConfig.Token,
                TokenType             = TokenType.Bot,
                LogLevel              = LogLevel.Debug,
                UseInternalLogHandler = true,
                ShardCount            = 1,
                ShardId               = 0
            };
            ServiceProvider deps = new ServiceCollection()
                                   .AddSingleton(httpClient)
                                   .AddSingleton(utility)
                                   .AddSingleton(new WeebShAPIClient(botConfig.WeebSHToken, httpClient))
                                   .AddDbContext <LanguageManager>(x => x.UseNpgsql(dBConfig.ConnString), ServiceLifetime.Transient)
                                   .AddDbContext <UserManager>(x => x.UseNpgsql(dBConfig.ConnString), ServiceLifetime.Transient)
                                   .BuildServiceProvider();
            CommandsNextConfiguration commandsNextConfiguration = new CommandsNextConfiguration
            {
                StringPrefixes = new [] { botConfig.BetaPrefix },
                Services       = deps
            };
            InteractivityConfiguration interactivityConfiguration = new InteractivityConfiguration
            {
                PaginationBehaviour = PaginationBehaviour.WrapAround,
                PaginationDeletion  = PaginationDeletion.DeleteEmojis,
                PollBehaviour       = PollBehaviour.DeleteEmojis
            };
            VoiceNextConfiguration voiceNextConfiguration = new VoiceNextConfiguration
            {
                AudioFormat = AudioFormat.Default
            };

            this.discordClient                = new DiscordClient(discordConfiguration);
            this.commandsNextExtension        = this.discordClient.UseCommandsNext(commandsNextConfiguration);
            this.interactivityExtension       = this.discordClient.UseInteractivity(interactivityConfiguration);
            this.voiceNextExtension           = this.discordClient.UseVoiceNext(voiceNextConfiguration);
            this.discordClient.ClientErrored += e =>
            {;
             Console.WriteLine("Client Error:");
             Console.WriteLine(e.EventName);
             Console.WriteLine(e.Exception);
             return(Task.CompletedTask); };
            this.discordClient.SocketErrored += e =>
            {
                Console.WriteLine("Socket Error:");
                Console.WriteLine(e.Exception);
                return(Task.CompletedTask);
            };
            this.discordClient.GuildDownloadCompleted += e =>
            {
                this.commandsNextExtension.RegisterCommands <Dev>();
                foreach (var f in Directory.EnumerateFiles(@"Commands\\"))
                {
                    using (ZipFile zip = ZipFile.Read(@$ "{f}"))
                    {
                        var dll           = zip.First(x => x.FileName.EndsWith(".dll"));
                        var splitFileName = dll.FileName.Split('.');
                        var group         = splitFileName[^ 2];
Example #18
0
        public Bot(IServiceProvider services)
        {
            var json = string.Empty;
            using (var fs = File.OpenRead("config.json"))
            using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                json =  sr.ReadToEnd();

            var configJson = JsonConvert.DeserializeObject<ConfigJson>(json);

            var config = new DiscordConfiguration()
            {
                Token = configJson.Token,
                TokenType = TokenType.Bot,
                AutoReconnect = true,
                LogLevel = LogLevel.Debug,
                UseInternalLogHandler = true
            };
            Client = new DiscordClient(config);

            Client.Ready += OnClientReady;


            var commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes = new string[] { configJson.Prefix },
                EnableMentionPrefix = true,
                EnableDms = false,
                DmHelp = true,
                Services =services
            };

            Commands = Client.UseCommandsNext(commandsConfig);
            Commands.RegisterCommands<FirstCommands>();
            Client.ConnectAsync();
        }
Example #19
0
        public static IServiceCollection AddDiscordService(this IServiceCollection services)
        {
            services.AddSingleton(serviceProvider =>
            {
                var config = serviceProvider.GetService <ClientConfig>();
                if (config == null)
                {
                    throw new InvalidOperationException(
                        "Add a ClientConfig to the dependencies");
                }

                //Not being used right now, but possibility for logging settings
                var logger = serviceProvider.GetRequiredService <ILoggerFactory>();

                //Configuration for the client.
                var discordConfig = new DiscordConfiguration
                {
                    Token           = config.Token,
                    TokenType       = TokenType.Bot,
                    LoggerFactory   = logger,
                    AutoReconnect   = true,
                    MinimumLogLevel = LogLevel.Debug,
                    //Setting the intents
                    Intents = DiscordIntents.AllUnprivileged
                              | DiscordIntents.Guilds
                };

                var client = new DiscordClient(discordConfig);

                //Return the service.
                return(client);
            });

            return(services.AddHostedService <Bot>());
        }
Example #20
0
        public void SetUp()
        {
            DiscordConfiguration configuration = new DiscordConfiguration();

            configuration.CommandPrefix = "@@";
            target = new AddDkpCommand(configuration, new Mock <IDkpProcessor>().Object, new Mock <ILogger <AddDkpCommand> >().Object);
        }
Example #21
0
        public DiscordConfiguration GetDiscordClientConfig()
        {
            _interactivity = new InteractivityConfiguration();
            // Create bot with config from json
            var json = string.Empty;

            using (var fs = File.OpenRead("config.json"))
            {
                using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                {
                    json = sr.ReadToEnd();
                }
            }
            var ConfigJson = JsonConvert.DeserializeObject <ConfigJson>(json);

            var config = new DiscordConfiguration
            {
                Token                 = ConfigJson.Token,
                TokenType             = TokenType.Bot,
                AutoReconnect         = true,
                LogLevel              = LogLevel.Debug,
                UseInternalLogHandler = true,
            };

            return(config);
        }
Example #22
0
        public async Task Start()
        {
            var cfg = new DiscordConfiguration()
            {
                Token     = discordToken,
                TokenType = TokenType.Bot,
                Intents   = DiscordIntents.All
            };

            var services = new ServiceCollection()
                           .AddSingleton <Random>()
                           .BuildServiceProvider();

            DiscordClient client = new DiscordClient(cfg);

            var commands = client.UseCommandsNext(new CommandsNextConfiguration()
            {
                Services       = services,
                StringPrefixes = new[] { "!" }
            });

            Handler handler = new Handler();

            commands.SetHelpFormatter <CustomHelpFormatter>();
            commands.CommandErrored += handler.CmdErroredHandler;

            client.VoiceStateUpdated += GetVoiceStateUpdatedHandler;

            await client.ConnectAsync();

            await Task.Delay(Timeout.Infinite);
        }
Example #23
0
        public Bot(string Token, string mysqlCon)
        {
            connection      = new MySqlConnection(mysqlCon);
            ShutdownRequest = new CancellationTokenSource();
            var cfg = new DiscordConfiguration
            {
                Token                 = Token,
                TokenType             = TokenType.Bot,
                AutoReconnect         = true,
                LogLevel              = LogLevel.Debug,
                UseInternalLogHandler = true
            };

            Client = new DiscordClient(cfg);
            Client.GuildDownloadCompleted += BotGuildsDownloaded;
            Client.GuildMemberAdded       += MemberAdd;
            Client.GuildMemberUpdated     += MemberUpdate;
            Client.GuildMemberRemoved     += MemberLeave;
            Client.GuildCreated           += BotGuildAdded;
            //Client.MessageReactionAdded += ReactAdd;
            //Client.MessageReactionRemoved += ReactRemove;
            CNext = Client.UseCommandsNext(new CommandsNextConfiguration {
                StringPrefixes    = new string[] { "$", "!", "%" },
                EnableDefaultHelp = false
            });
            CNext.RegisterCommands <Commands.UserCommands>();
            CNext.RegisterCommands <Commands.AdminCommands>();
            CNext.RegisterCommands <Commands.OwnerCommands>();
            CNext.RegisterCommands <Config.UserConfig>();
            INext = Client.UseInteractivity(new InteractivityConfiguration {
            });
        }
Example #24
0
        async Task MainAsync()
        {
            if (!System.IO.File.Exists("secret.txt"))
            {
                throw new Exception("secret.txt was not found. Create secret.txt and put your bot's token in there. https://discord.foxbot.me/stable/guides/getting_started/first-bot.html#creating-a-discord-bot");
            }

            DiscordConfiguration discordConfiguration = new DiscordConfiguration()
            {
                Token                 = System.IO.File.ReadAllLines("secret.txt")[0],
                TokenType             = TokenType.Bot,
                UseInternalLogHandler = true,
                LogLevel              = LogLevel.Debug
            };

            CommandsNextConfiguration commandsNext = new CommandsNextConfiguration()
            {
                StringPrefix  = "!",
                CaseSensitive = false,
            };


            DiscordClient = new DiscordClient(discordConfiguration);
            Commands      = DiscordClient.UseCommandsNext(commandsNext);

            Commands.RegisterCommands <Commands>();
            Commands.CommandErrored += Commands_CommandErrored;

            await DiscordClient.ConnectAsync();

            await Task.Delay(-1);
        }
        public async Task RunAsyncBot()
        {
            var json = string.Empty;

            using (var fs = File.OpenRead("config.json"))
                using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                    json = await sr.ReadToEndAsync().ConfigureAwait(false);

            var configJson = JsonConvert.DeserializeObject <ConfigJson>(json);
            var config     = new DiscordConfiguration
            {
                Token         = configJson.Token,
                TokenType     = TokenType.Bot,
                AutoReconnect = true,
                LogLevel      = LogLevel.Debug,
            };

            Client = new DiscordClient(config);

            Client.Ready += OnClientReady;
            var commandsConfig = new CommandsNextConfiguration
            {
            };

            Commands = Client.UseCommandsNext(commandsConfig);

            await Client.ConnectAsync();

            await Task.Delay(1);
        }
Example #26
0
        private DiscordConfiguration SetupDiscordConfig(ConfigJson config)
        {
            Console.WriteLine("Configuring client");

            // Setup loglevel based on config file string
            LogLevel ll = new LogLevel();

            switch (config.LogLevel)
            {
            case "debug": ll = LogLevel.Debug; break;

            case "info": ll = LogLevel.Info; break;

            case "critical": ll = LogLevel.Critical; break;

            case "error": ll = LogLevel.Error; break;

            case "warning": ll = LogLevel.Warning; break;

            default: ll = LogLevel.Info; break;
            }

            // Setup discord config object
            DiscordConfiguration cfg = new DiscordConfiguration {
                Token     = config.Token,
                TokenType = TokenType.Bot,

                AutoReconnect         = true,
                LogLevel              = ll,
                UseInternalLogHandler = true
            };

            return(cfg);
        }
Example #27
0
        public async Task Connect(Configuration config)
        {
            DiscordConfig = config;
            var discordConfig = new DiscordConfiguration
            {
                Token     = config.Token,
                TokenType = TokenType.Bot,

                AutoReconnect         = true,
                LogLevel              = LogLevel.Debug,
                UseInternalLogHandler = true
            };

            DiscordClient = new DiscordClient(discordConfig);
            DiscordClient.SetWebSocketClient <WebSocket4NetCoreClient>();
            DiscordClient.MessageCreated         += MessageCreated;
            DiscordClient.MessageReactionAdded   += ReactionAdded;
            DiscordClient.MessageReactionRemoved += ReactionRemoved;
            DiscordClient.ClientErrored          += ClientError;
            DiscordClient.SocketErrored          += SocketError;


            await DiscordClient.ConnectAsync();

            if (DiscordConfig.ChannelId != 0)
            {
                Channel = await DiscordClient.GetChannelAsync(DiscordConfig.ChannelId);
            }

            StartTime = DateTime.UtcNow;
        }
Example #28
0
        public Bot()
        {
            var discordConfig = new DiscordConfiguration
            {
                Token     = Settings.GetSettings().DiscordToken,
                TokenType = TokenType.Bot,
                Intents   = DiscordIntents.All
            };

            var commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes = new List <string>()
                {
                    "?"
                },
                EnableDefaultHelp = false
            };

            Discord = new DiscordClient(discordConfig);

            Discord.GuildAvailable   += Discord_GuildAvailable;
            Discord.GuildMemberAdded += Discord_GuildMemberAdded;

            CommandService = Discord.UseCommandsNext(commandsConfig);

            CommandService.RegisterCommands(typeof(Commands));
            CommandService.RegisterCommands(typeof(PeerCommands));
        }
Example #29
0
        public async Task RunAsync()
        {
            ConfigJson configJson = await GetConfig();

            if (Token != null)
            {
                configJson.Token = Token;
                await UpdateConfig(configJson);
            }
            DiscordConfiguration config = new DiscordConfiguration
            {
                Token           = Token ?? configJson.Token,
                TokenType       = TokenType.Bot,
                AutoReconnect   = true,
                MinimumLogLevel = LogLevel.Debug,
            };

            Client                   = new DiscordClient(config);
            Client.Ready            += OnClientReady;
            Client.GuildMemberAdded += OnMemberAdded;

            CommandsNextConfiguration commandsConfig = new CommandsNextConfiguration
            {
                StringPrefixes      = new string[] { configJson.Prefix },
                EnableMentionPrefix = true,
                EnableDms           = false
            };

            Commands = Client.UseCommandsNext(commandsConfig);
            Commands.RegisterCommands <DummyCommands>();

            await Client.ConnectAsync();

            await Task.Delay(-1);
        }
 public void SetUp()
 {
     configuration = new DiscordConfiguration();
     configuration.CommandPrefix = ".dkp ";
     state  = new AuctionState();
     target = new RevealBidsCommand(configuration, state, new Mock <ILogger <RevealBidsCommand> >().Object);
 }