Exemple #1
0
        public static async Task SetGame()
        {
            AltConsole.Print("Client", "Game", "Setting game message...");
            await _client.SetGameAsync(Config.Game);

            AltConsole.Print("Client", "Game", "Game has been set.");
        }
Exemple #2
0
        public async Task Run(string[] args)
        {
            AltConsole.Print("Hearthstone Bot has started up...");

            _args = args;

            ParseArgs();
            Config.Initialize();

            _client = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel            = LogSeverity.Verbose,
                WebSocketProvider   = WS4NetProvider.Instance,
                MessageCacheSize    = 1000,
                AlwaysDownloadUsers = true,
            });
            _commands = new CommandService(new CommandServiceConfig
            {
                DefaultRunMode = RunMode.Async,
                LogLevel       = LogSeverity.Verbose,
            });

            InitializeLogging();
            InitializeServices();
            Events.Initialize(_client, _commands);

            await LoginAndConnect();

            await Task.Delay(-1);
        }
Exemple #3
0
        public static async Task CommandHandler(SocketMessage possibleCmd)
        {
            var message = possibleCmd as SocketUserMessage;

            if (message == null || message.Author.IsBot)
            {
                return;
            }

            var    argPos = 0;
            string prefix;

            if (message.Channel is SocketDMChannel)
            {
                prefix = "h^";
            }
            else
            {
                prefix = Settings.GetPrefix((message.Channel as SocketGuildChannel).Guild.Id);
            }

            //if message is a command and doesnt just contain the prefix
            if ((message.HasStringPrefix(prefix, ref argPos) ||
                 message.HasMentionPrefix(_client.CurrentUser, ref argPos)) &&
                message.Content.Trim() != prefix)
            {
                var context = new SocketCommandContext(_client, message);

                if (message.Channel is SocketDMChannel)
                {
                    AltConsole.Print("Command", "DM", $"{(message.Channel as SocketDMChannel).Recipient.Username}");
                    AltConsole.Print("Command", "DM", $"{message.Content}");
                }
                else
                {
                    AltConsole.Print("Command", "Guild", $"{(message.Channel as SocketGuildChannel).Guild.Name}");
                    AltConsole.Print("Command", "Guild", $"{message.Content}");
                }

                var result = await _commands.ExecuteAsync(context, argPos, _services);

                if (!result.IsSuccess)
                {
                    if (result.ErrorReason.ToLower().Contains("unknown command"))
                    {
                        return;
                    }

                    await context.Channel.SendMessageAsync("There was an error in the command.");

                    //await context.Channel.SendMessageAsync("https://goo.gl/JieFJM");

                    AltConsole.Print("Error", "Error", result.ErrorReason);
                    //debug purposes
                    //await context.Channel.SendMessageAsync($"**Error:** {result.ErrorReason}");
                }
            }
        }
Exemple #4
0
        public async Task LoginAndConnect()
        {
            string token = _isTestRun ? Config.TestToken : Config.BotToken;

            AltConsole.Print("Client", "Gateway", "Logging in...");
            await _client.LoginAsync(TokenType.Bot, token);

            AltConsole.Print("Client", "Gateway", "Logged in.");
            AltConsole.Print("Client", "Gateway", "Starting up...");
            await _client.StartAsync();

            AltConsole.Print("Client", "Gateway", "Finished starting up...");
        }
Exemple #5
0
        public static void Initialize()
        {
            AltConsole.Print("Config", "Config", "Initializing configuration...");

            var manager = Resources.ResourceManager;

            BotToken         = manager.GetString("BotToken");
            TestToken        = manager.GetString("TestToken");
            Game             = manager.GetString("Game");
            BlueDiscordBots  = manager.GetString("BlueDiscordBots");
            BlackDiscordBots = manager.GetString("BlackDiscordBots");

            AltConsole.Print("Config", "Config", "Configuration initialized.");
        }
Exemple #6
0
 public static Task Log(LogMessage message)
 => Task.Run(() => AltConsole.Print(message.Severity, message.Source, message.Message, message.Exception));