Example #1
0
        public async Task HandleCommand(SocketMessage messageParam)
        {
            var message = messageParam as SocketUserMessage;

            if (message == null)
            {
                return;
            }
            int argPos = 0;

            if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos)))
            {
                return;
            }
            var context = new SocketCommandContext(client, message);
            var result  = await commands.ExecuteAsync(context, argPos, services);

            if (!result.IsSuccess)
            {
                await context.Channel.SendMessageAsync(result.ErrorReason);
            }
        }
Example #2
0
        private async Task HandleCommandAsync(SocketMessage messageParam)
        {
            if (!(messageParam is SocketUserMessage message))
            {
                return;
            }

            int argPos = 0;

            if (!(message.HasCharPrefix('!', ref argPos) ||
                  message.HasMentionPrefix(_client.CurrentUser, ref argPos)) || message.Author.IsBot)
            {
                return;
            }

            SocketCommandContext context = new SocketCommandContext(_client, message);

            await _commands.ExecuteAsync(
                context,
                argPos,
                null);
        }
Example #3
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            var message = arg as SocketUserMessage;
            var context = new SocketCommandContext(_client, message);

            if (message.Author.IsBot)
            {
                return;
            }

            int position = 0;

            if (message.HasStringPrefix("!", ref position))
            {
                var result = await _commands.ExecuteAsync(context, position, _services);

                if (!result.IsSuccess)
                {
                    Console.WriteLine(result.ErrorReason);
                }
            }
        }
Example #4
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            var msg = arg as SocketUserMessage;

            if (msg == null)
            {
                return;
            }
            var context = new SocketCommandContext(_client, msg);
            int argPos  = 0;

            if (msg.HasStringPrefix(Config.bot.cmdPrefix, ref argPos) ||
                msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                var result = await _service.ExecuteAsync(context, argPos, null, MultiMatchHandling.Best);

                if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
                {
                    Console.WriteLine(result.ErrorReason);
                }
            }
        }
Example #5
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            var message = arg as SocketUserMessage;

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

            int argPos = 0;

            if (message.HasStringPrefix("!!", ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                var context = new SocketCommandContext(_client, message);

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

                if (!result.IsSuccess)
                {
                    Console.WriteLine(result.ErrorReason);
                }
            }
        }
Example #6
0
        private async Task HandleCommandAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;

            if (msg == null)
            {
                return;
            }

            var context = new SocketCommandContext(_client, msg);

            int argPos = 123;

            if (msg.HasStringPrefix("gil ", ref argPos) || msg.HasStringPrefix("Gil ", ref argPos))
            {
                var result = await _service.ExecuteAsync(context, argPos);

                if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
                {
                    await context.Channel.SendMessageAsync(result.ErrorReason);
                }
            }
        }
Example #7
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            var msg = arg as SocketUserMessage;

            if (msg == null)
            {
                return;
            }

            if (msg.Author.Id == _client.CurrentUser.Id || msg.Author.IsBot)
            {
                return;
            }

            int pos = 0;

            if (msg.HasCharPrefix('.', ref pos) || msg.HasMentionPrefix(_client.CurrentUser, ref pos))
            {
                var context = new SocketCommandContext(_client, msg);

                var result = await _commands.ExecuteAsync(context, pos, _services);
            }
        }
        private async Task HandleCommandAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;

            if (msg == null)
            {
                return;
            }
            var context = new SocketCommandContext(_client, msg);

            if (context.User.IsBot)
            {
                return;
            }

            MessageLevelSystem.AddXpForMessage((SocketGuildUser)context.User, (SocketTextChannel)context.Channel);
            UserAccount account = UserManager.GetAccount(context.User);

            account.MessageCount++;
            UserManager.SaveAccounts();

            int argPos = 0;

            if (msg.HasCharPrefix(ConfigHandler.config.Prefix, ref argPos) ||
                msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                var result = await _service.ExecuteAsync(
                    context : context,
                    argPos : argPos,
                    services : null);

                if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
                {
                    Console.WriteLine(result.ErrorReason);
                }
            }
        }
Example #9
0
        public async Task HandleCommand(SocketMessage messageParam)
        {
            if (messageParam.Author.Id == client.CurrentUser.Id)
            {
                return;
            }
            // Don't process the command if it was a System Message
            var message = messageParam as SocketUserMessage;

            if (message == null)
            {
                return;
            }
            // Create a number to track where the prefix ends and the command begins
            int argPos = 0;
            // Create a Command Context
            var context = new CommandContext(client, message);

            // Determine if the message is a command, based on if it starts with '!' or a mention prefix
            if (message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))
            {
                // Execute the command. (result does not indicate a return value,
                // rather an object stating if the command executed succesfully)
                var result = await commands.ExecuteAsync(context, argPos, map);

                if (!result.IsSuccess)
                {
                    await context.Channel.SendMessageAsync(result.ErrorReason);
                }
            }
            var keywordResult = await KeywordChecker.ExecuteAsync(message, context);

            if (!keywordResult.IsSuccess)
            {
                await context.Channel.SendMessageAsync(keywordResult.ErrorReason);
            }
        }
Example #10
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            var message = arg as SocketUserMessage; //create message

            if (message is null || message.Author.IsBot)
            {
                return;     //if it is null, or if the the author is a bot, ignore
            }
            int argPos = 0; //pointer which prefix ends


            //if message starts as ! or if someone mentions the bot
            if (message.HasStringPrefix("!", ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                var context = new SocketCommandContext(_client, message);              //create socket comand context, give client and message

                var result = await _commands.ExecuteAsync(context, argPos, _services); //execute command, pass context, the position, and the services

                if (!result.IsSuccess)
                {
                    Console.WriteLine(result.ErrorReason);
                }
            }
        }
Example #11
0
        private async Task OnMessageReceived(SocketMessage arg)
        {
            int argPos = 0;

            // Should only trigger message created by user if not, return.
            if (arg is not SocketUserMessage message)
            {
                return;
            }
            // Makes sure a bot edit on a user message does not trigger bot.
            if (message.Source != MessageSource.User)
            {
                return;
            }
            //Bot only triggers if tagged or prefix is correct.
            if (!message.HasStringPrefix(_config["prefix"], ref argPos) &&
                !message.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                return;
            }

            SocketCommandContext context = new(_client, message);
            await _service.ExecuteAsync(context, argPos, _provider);
        }
Example #12
0
        private async Task _client_MessageReceived(SocketMessage arg)
        {
            var message = arg as SocketUserMessage;

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

            int argPos = 0;

            Game game = GameInteractive._games.SingleOrDefault(x => x._RoomID == message.Channel.Id);

            if (game != null)
            {
                game.MessegeResive(message);
                return;
            }

            if (!message.Channel.Name.Equals("gamecontrol"))
            {
                return;
            }

            if (message.HasStringPrefix("&", ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                //Console.WriteLine(message.ToString() + $": {argPos}");
                var context = new SocketCommandContext(_client, message);
                var result  = await _commands.ExecuteAsync(context, argPos, _services);

                if (!result.IsSuccess)
                {
                    Console.WriteLine(result.ErrorReason);
                }
            }
        }
Example #13
0
        private async Task HandleCommandAsync(SocketMessage arg)
        {
            var msg    = arg as SocketUserMessage;
            int argPos = 0;

            if (msg is null || msg.Author.IsBot || !msg.HasCharPrefix('$', ref argPos))
            {
                return;
            }

            var context = new SocketCommandContext(SocketClient, msg);
            var result  = await _commands.ExecuteAsync(context, argPos, _services);

            if (!result.IsSuccess)
            {
                await context.Channel.SendMessageAsync($"Command was not successful: {result.ErrorReason}");

                return;
            }
            var options = new RequestOptions {
                RetryMode = RetryMode.AlwaysRetry
            };
            //await msg.DeleteAsync(options);
        }
Example #14
0
        private async Task HandleUserCommand(SocketMessage socketMessage)
        {
            if (socketMessage is SocketUserMessage userMessage)
            {
                int argumentPosition = 0;

                bool hasCommandPrefix = userMessage.HasCharPrefix(COMMAND_PREFIX, ref argumentPosition);

                if (hasCommandPrefix)
                {
                    var commandContext = new SocketCommandContext(_client, userMessage);

                    await _commandService.ExecuteAsync(commandContext, argumentPosition, null);
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }
Example #15
0
        /// <summary>
        /// Called when a message is received in either a channel or DM.
        /// Checks if the message contains a banned word and purges and warns if it does.
        /// If the message is a command, checks if the guild has a bot spam channel and if it does, if the message is posted in there.
        /// Gives one gold per non-command message sent.
        /// </summary>
        /// <param name="MessageParam">Information about the message sent.</param>
        public async Task Client_MessageReceived(SocketMessage MessageParam)
        {
            SocketUserMessage    Message = MessageParam as SocketUserMessage;
            SocketCommandContext Context = new SocketCommandContext(Client, Message);

            //Make sure the message isn't empty
            if (Context.Message == null || Context.User.IsBot)
            {
                return;
            }

            //Channel to send the chat logs in
            ulong channel = Data.GetChatLogChannel(Context.Guild.Id);

            if (channel != 0)
            {
                try
                {
                    SocketTextChannel channelPost = Context.Guild.GetTextChannel(channel);

                    //Format: Name#1111: "This is a sentence." -- #channel at 1/11/1111 1:11:11 PM EST
                    timeUtc = DateTime.UtcNow;
                    today   = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, easternZone);
                    if (Context.Message.Content == "")
                    {
                        await channelPost.SendMessageAsync($"{Context.Message.Author} uploaded an image. -- <#{Context.Channel.Id}> at {today} EST");
                    }
                    else
                    {
                        await channelPost.SendMessageAsync($"{Context.Message.Author}: \"{Context.Message}\" -- <#{Context.Channel.Id}> at {today} EST");
                    }
                }
                catch (Exception)
                {
                }
            }

            //If message is blank (picture/file), return after chat log
            if (Context.Message.Content == "")
            {
                return;
            }

            //Get the permissions of the user for use in checking for banned words and checking the bot spam channel
            SocketGuildUser User = Context.User as SocketGuildUser;

            //Make sure the message has no banned words
            //If it contains a banned word, purge the message and issue a warning
            //Three warnings and offender gets kicked
            if (Data.GetBannedWords(Context.Guild.Id).Length > 0 && User.GuildPermissions.KickMembers == false)
            {
                foreach (string word in Data.GetBannedWords(Context.Guild.Id))
                {
                    if (Message.Content.ToLower().Contains(word))
                    {
                        try
                        {   //get the author of the message
                            IGuildUser GuildUser = (IGuildUser)Message.Author;
                            ulong      userid    = GuildUser.Id;
                            ulong      guildid   = Context.Guild.Id;
                            string     username  = GuildUser.Username;

                            //Get the message and delete it, issue a warning
                            await(Context.Channel as SocketTextChannel).DeleteMessageAsync(Context.Message.Id);
                            await Data.AddWarnings(Context.User.Id, Context.Guild.Id, Context.User.Username);

                            int amountOfWarnings = Data.GetWarnings(userid, guildid);

                            //For the mod log to know which moderator to put
                            SocketUser Nephry = Context.Guild.GetUser(322806920203337740);

                            //If warnings is 3 or more, kick the offender if bot has kick permissions
                            if (amountOfWarnings >= 3)
                            {
                                IRole nephry = null;
                                foreach (IRole role in Context.Guild.Roles)
                                {
                                    if (role.Name == "Nephry")
                                    {
                                        nephry = role;
                                        break;
                                    }
                                }

                                if (nephry == null)
                                {
                                    return;
                                }

                                if (nephry.Permissions.KickMembers == false)
                                {
                                    return;
                                }

                                await GuildUser.SendMessageAsync("You were kicked for accumulating too many warnings.");

                                await Context.Channel.SendMessageAsync($"{GuildUser.Mention} has been kicked for accumulating too many warnings.");

                                await GuildUser.KickAsync("Accumulated too many warnings");

                                await Data.RemoveWarnings(userid, guildid, username, amountOfWarnings);

                                await ModLog.PostInModLog(Context.Guild, "Auto-Kicked", Nephry, GuildUser, "Accumulated too many warnings.");

                                return;
                            }
                            await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you have been warned for using inappropriate language. Please type \"!getbannedwords\" " +
                                                                   $"to see a list of banned words in this server. " +
                                                                   $"You now have {Data.GetWarnings(Context.User.Id, Context.Guild.Id)} warning(s).");

                            await ModLog.PostInModLog(Context.Guild, "Auto-Warn", Nephry, GuildUser, "Used inappropriate language.");

                            return;
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }

            int ArgPos = 0;

            //Make sure the message doesn't start with ! for the gold bonus
            if (!Message.HasCharPrefix('!', ref ArgPos))
            {
                await Data.SaveGold(Context.User.Id, 1, Context.Guild.Id, Context.User.Username); //Add one gold per message
            }
            //If message does not start with ! or bot mention, return
            if (!(Message.HasCharPrefix('!', ref ArgPos) || Message.HasMentionPrefix(Client.CurrentUser, ref ArgPos)))
            {
                return;
            }

            //Get the bot spam channel if there is one assigned
            //and make sure the command is in that channel
            if (Data.GetBotSpamChannel(Context.Guild.Id) != 0)
            {
                //put channel bot spam here and make sure the message is either in the correct channel, has kick or admin permissions
                if (Context.Channel.Id == Data.GetBotSpamChannel(Context.Guild.Id) || User.GuildPermissions.KickMembers == true ||
                    User.GuildPermissions.Administrator == true)
                {
                    IResult Results = await Commands.ExecuteAsync(Context, ArgPos, null);

                    if (!Results.IsSuccess)
                    {
                        CustomCommand customCommands = new CustomCommand();
                        await customCommands.UseCustomCommand(Context);
                    }
                    return;
                }
                else
                {
                    return;
                }
            }
            //Search for a matching command and execute it
            IResult Result = await Commands.ExecuteAsync(Context, ArgPos, null);

            if (!Result.IsSuccess)
            {
                CustomCommand customCommands = new CustomCommand(); //If a hard-coded command isn't found, use the server's custom commands instead
                await customCommands.UseCustomCommand(Context);
            }
        }
Example #16
0
        private async Task HandleCommandAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;

            if (msg == null)
            {
                return;
            }

            var Context = new SocketCommandContext(_client, msg);

            //Check Anti SPAM
            if (SlowMode && (!Iterations.HasRole((SocketGuildUser)Context.User, "Bots") &&
                             !Iterations.HasRole((SocketGuildUser)Context.User, "Mod") &&
                             !Iterations.HasRole((SocketGuildUser)Context.User, "Admin") &&
                             !Iterations.HasRole((SocketGuildUser)Context.User, "Junior Dev") &&
                             !Iterations.HasRole((SocketGuildUser)Context.User, "Supervisor") &&
                             !Iterations.HasRole((SocketGuildUser)Context.User, "Owner") &&
                             Message.Contains(Context.User.Id)))
            {
                Message message = Message.Get(Context.User.Id);

                Console.WriteLine("User: "******" Messages: {0}/{1} Warns: {2}/{3}", message.Count, maxMessagesPerInterval, message.Warns, 3);

                if (message.Count >= maxMessagesPerInterval)
                {
                    Message.SetWarnCount(Context.User.Id);

                    if (message.Warns > 3)
                    {
                        //Nothing yet
                    }

                    await Context.Message.DeleteAsync();
                }
                else
                {
                    Message.SetMsgCount(Context.User.Id);
                }
            }
            else
            {
                Cache.AntiSpam.Add(new Message(Context.User.Id, 1));
            }

            int argPos = 0;

            if (msg.HasCharPrefix('$', ref argPos))
            {
                if (msg.Content.ToLower().Contains("$gk"))
                {
                    await msg.DeleteAsync();

                    return;
                }

                requestCount++;

                Console.WriteLine("Request number " + requestCount + " Out of " + maxRequestsPerSecond);

                if (requestCount > maxRequestsPerSecond)
                {
                    return;
                }

                Console.WriteLine("Command: " + Context.Message);
                var result = await _service.ExecuteAsync(Context, argPos);

                if (!result.IsSuccess)// && result.Error != CommandError.UnknownCommand)
                {
                    Console.WriteLine("Command Error: " + result.Error.ToString());
                    await Context.Channel.SendMessageAsync(result.ErrorReason);
                }
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && ((msg.Content.ToLower().Contains("download") && (msg.Content.ToLower().Contains("it") || msg.Content.ToLower().Contains("?"))) || msg.Content.ToLower().Contains(" cheat") || msg.Content.ToLower().Contains("loader") || msg.Content.ToLower().Contains("mod ") || msg.Content.ToLower().Contains("hack") || msg.Content.ToLower().Contains("menu") || msg.Content.ToLower().Contains("gk") || ((msg.Content.ToLower().Contains("gk") && msg.Content.ToLower().Contains("cs")) || (msg.Content.ToLower().Contains("gk") && msg.Content.ToLower().Contains("gta")))))
            {
                //Check Anti SPAM
                if (SlowMode && (!Iterations.HasRole((SocketGuildUser)Context.User, "Bots") &&
                                 !Iterations.HasRole((SocketGuildUser)Context.User, "Mod") &&
                                 !Iterations.HasRole((SocketGuildUser)Context.User, "Admin") &&
                                 !Iterations.HasRole((SocketGuildUser)Context.User, "Junior Dev") &&
                                 !Iterations.HasRole((SocketGuildUser)Context.User, "Supervisor") &&
                                 !Iterations.HasRole((SocketGuildUser)Context.User, "Owner")))
                {
                    await Context.User.SendMessageAsync("Discords Terms of Service Prohibit Sharing of 'Cheats', therefore you can find our Software on our Website." + "\n"
                                                        + "Software Download is on the forum: " + "\n"
                                                        + "https://MaverickCheats.eu/");

                    await Context.Message.DeleteAsync();
                }
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && msg.Content.ToLower().Contains("activation") || msg.Content.ToLower().Contains("acitvate") || msg.Content.ToLower().Contains("license") || (msg.Content.ToLower().Contains("key") && msg.Content.ToLower().Contains("?")))
            {
                await Context.User.SendMessageAsync("License Keys are no longer required for the cheat, just login using your Forum Email and Password and you will have access to all the Free cheats.");

                await Context.Message.DeleteAsync();
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && msg.Content.ToLower().Contains("hwid") && msg.Content.ToLower().Contains("taken"))
            {
                await Context.Channel.SendMessageAsync("HWID Taken means you have a Login already, please use your current account.");
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && msg.Content.ToLower().Contains("hwid") && msg.Content.ToLower().Contains("invalid"))
            {
                await Context.Channel.SendMessageAsync("Invalid HWID means your Computer Identity has changed, ask staff for a reset.");
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && msg.Content.ToLower().Contains("invalid") && msg.Content.ToLower().Contains("username"))
            {
                await Context.Channel.SendMessageAsync("Invalid Username means there is no account associated to that username, there may have been a database reset recently and you may need to register again.");
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && ((msg.Content.ToLower().Contains("stealth") && msg.Content.ToLower().Contains("broke")) || (msg.Content.ToLower().Contains("stealth") && msg.Content.ToLower().Contains("cant")) || (msg.Content.ToLower().Contains("stealth") && msg.Content.ToLower().Contains("wont")) || (msg.Content.ToLower().Contains("stealth") && msg.Content.ToLower().Contains("isnt"))))
            {
                await Context.Channel.SendMessageAsync("Stealth is buggy and may not work, if you encounter this issue you can try changing servers and restarting your game to help fix the issue.");
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && msg.Content.ToLower().Contains("server down"))
            {
                await DiscordBot.Functions.Status.GetStatus(msg, Context);
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && msg.Content.ToLower() == "crash")
            {
                await Context.Channel.SendMessageAsync("If you have crashes when you immediately start your MaverickClient or Updater, you NEED to disable ALL POSSIBLE SECURITY that may block the connection. This cannot be fixed by us as AntiVirus's and Firewalls autoblock suspicous servers such as our 'Server'.");
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && (msg.Content.ToLower().Contains("vehicle") && msg.Content.ToLower().Contains("spawn") || msg.Content.ToLower().Contains("kicks") && msg.Content.ToLower().Contains("out") & msg.Content.ToLower().Contains("out")) && msg.Author.Id != _client.CurrentUser.Id)
            {
                Console.WriteLine(msg.Author.Id + "!=" + _client.CurrentUser.Id);

                await Context.Channel.SendMessageAsync("If you're having issues with vehicles, ensure the bypass is enabled by going to the Spawn Tab, Vehicles and then Options at the top.");
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && msg.Content.ToLower().Contains("send") && msg.Content.ToLower().Contains("logs"))
            {
                Console.WriteLine("Logs Called");

                EmbedBuilder eb = new EmbedBuilder();
                eb.WithTitle("Finding our Logs");
                eb.AddInlineField("Loader Logs", "Opening MaverickClient shows a Black Console, right click the top of the console, click edit, click select all and press enter. You can now press CTRL + V in discord to paste the logs.");
                eb.AddInlineField("Game Logs", "Press Windows Key + R while on the Desktop.\nType in: %appdata%\\CrispyCheats\\ and press enter.");
                eb.Color = new Color(0, 255, 0);

                await msg.Channel.SendMessageAsync("", false, eb);
            }
            else if (msg.Author.Id != _client.CurrentUser.Id && msg.Content.ToLower().Contains("menu") && msg.Content.ToLower().Contains("open"))
            {
                Console.WriteLine("Menu Open Called");

                EmbedBuilder eb = new EmbedBuilder();
                eb.WithTitle("Menu Navigation");
                eb.AddInlineField("Open Menu", "Numpad -");
                eb.AddInlineField("Save Config", "L");
                eb.AddInlineField("Unload Menu", "F9");

                eb.AddInlineField("Tab Left", "Numpad 7");
                eb.AddInlineField("Menu Up", "Numpad 8");
                eb.AddInlineField("Tab Right", "Numpad 9");

                eb.AddInlineField("Menu Left", "Numpad 4");
                eb.AddInlineField("Toggle Option", "Numpad 5");
                eb.AddInlineField("Menu Right", "Numpad 6");
                eb.AddInlineField("Menu Back", "Numpad 0");
                eb.AddInlineField("Menu Down", "Numpad 2");
                eb.AddInlineField("Num Lock", "Toggles Controls");
                eb.Color = new Color(0, 255, 0);
                eb.Title = "Menu Keybinds";

                await msg.Channel.SendMessageAsync("", false, eb);
            }
        }
Example #17
0
        private async Task _client_MessageReceived(SocketMessage arg)
        {
            var message = arg as SocketUserMessage;
            var context = new SocketCommandContext(_client, message);

            latency = _client.Latency;


            if (context.IsPrivate == true && context.User.IsBot == false) //If they send a DM to Quantum bot
            {
                var Ray = _client.GetUser(ServerConfigData.PointersAnonUserID["Ray Soyama"]);
                await Ray.SendMessageAsync($"DM to Quantum Bot\n" +
                                           $"Time: {arg.Timestamp}\n" +
                                           $"Channel: {arg.Channel}\n" +
                                           $"Discord ID: {arg.Author.Id}\n" +
                                           $"Message: {arg.ToString()}\n");
            }
            else if (context.User.IsBot == false)
            {
                string chatLog = $"\n\n" +
                                 $"Time: {arg.Timestamp}\n" +
                                 $"Channel: {arg.Channel}\n" +
                                 $"Msg ID: {arg.Id}\n" +
                                 $"User ID: {arg.Author.Id}\n" +
                                 $"Username: {((IGuildUser)arg.Author).Nickname}\n" +
                                 $"Message: {arg}\n";

                foreach (var FileLink in arg.Attachments)
                {
                    chatLog += $"File: {FileLink.Url}\n";
                }

                Console.WriteLine(chatLog);
                File.AppendAllText(logFileSavePath, chatLog);
            }


            //Music bot cleansing
            int argPos = 0;

            if (context.Channel.Id.Equals(ServerConfigData.PointersAnonChatID["Music"]))
            {
                if (context.Message.HasCharPrefix('!', ref argPos))
                {
                    //this can cause issues, so care
                    await Task.Run(() => WaitThenDeleteMessage(context.Message));

                    return;
                }
                else if (context.User.Id == ServerConfigData.PointersAnonUserID["Rythm Bot"])
                {
                    await Task.Run(() => WaitThenDeleteMessage(context.Message));

                    return;
                }
            }



            if (context.Message == null || context.Message.Content.ToString() == "" || context.User.IsBot == true) //Checks if the msg is from a user, or bot
            {
                return;
            }


            #region Custom Word Checks
            if (context.Message.ToString().ToLower().Contains("good bot"))
            {
                await context.Channel.SendMessageAsync("Thank you! You're a good human <a:partyparrot:647210646177447936>");
            }
            else if (context.Message.ToString().ToLower().Contains("happy birthday"))
            {
                var msg = await context.Channel.SendMessageAsync("<a:rave:647212416618332161>~Happy Birthday!~<a:rave:647212416618332161>");

                //var emoji = new Emoji("\uD83D\uDC4C");
                //await msg.AddReactionAsync(emoji);
            }

            #endregion



            if (!(message.HasCharPrefix(ServerConfigData.prefix, ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos))) //Checks for Prefix or @Quantum Bot
            {
                return;
            }

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

            //if bot command is good
            if (result.IsSuccess == true)
            {
                //If Admin, don't ping
                var AuthRole = context.Guild.GetRole(Program.ServerConfigData.PointersAnonRoleID["Admin"]);

                SocketGuildUser user = context.User as SocketGuildUser;
                if (user.Roles.Contains(AuthRole))
                {
                    //Forward Msg to bot history
                    await context.Guild.GetTextChannel(Program.ServerConfigData.PointersAnonChatID["Bot History"]).SendMessageAsync($"Command Invoked:\n" +
                                                                                                                                    $"Message - \"{context.Message.ToString()}\"\n" +
                                                                                                                                    $"User - Admin: {user.Nickname} \n" +
                                                                                                                                    $"Channel - <#{context.Channel.Id}>\n" +
                                                                                                                                    $"Time - {DateTime.Now}");
                }
                else
                {
                    //Forward Msg to bot history
                    await context.Guild.GetTextChannel(Program.ServerConfigData.PointersAnonChatID["Bot History"]).SendMessageAsync($"Command Invoked:\n" +
                                                                                                                                    $"Message - \"{context.Message.ToString()}\"\n" +
                                                                                                                                    $"User - <@{context.Message.Author.Id}>\n" +
                                                                                                                                    $"Channel - <#{context.Channel.Id}>\n" +
                                                                                                                                    $"Time - {DateTime.Now}");
                }
            }
            else if (result.IsSuccess == false) //If the command failed, run this
            {
                //await context.Guild.GetTextChannel(Program.ServerConfigData.PointersAnonChatID["Bot History"]).SendMessageAsync($"Command Invoked and Failed <@{ServerConfigData.PointersAnonUserID["Ray Soyama"]}>:\n" +
                //                                                                                                                          $"Message - \"{context.Message.ToString()}\"\n" +
                //                                                                                                                          $"User - <@{context.Message.Author.Id}>\n" +
                //                                                                                                                          $"Channel - <#{context.Channel.Id}>\n" +
                //                                                                                                                          $"Time - {DateTime.Now}");
            }
        }
Example #18
0
        }                                                                                    //The true main, but we want it run async, so we only call OUR version of main

        private static async Task MainAsync(string[] args)
        {
            var client = new DiscordSocketClient();
            SocketTextChannel defaultChannel = null;

            Random randomQuote = new Random();

            string[] loginQuotes = { "It's time to kick ass and chew bubble gum", "Your face, your ass - what's the difference?", "Hail to The King Baby", "Let's Rock", "Shake it baby!" };
            //End setup for stupid one liner login quotes

            client.Log += message => { //Logging ready status to whoever is running the client
                Console.WriteLine(message);
                return(Task.CompletedTask);
            };
            //Setup stuff
            var serviceProvider = new ServiceCollection().BuildServiceProvider();
            var commandService  = new CommandService();
            await commandService.AddModulesAsync(Assembly.GetEntryAssembly());

            client.MessageReceived += async rawMessage => {//MessageReceived..so we need to go in here and figure out what to do
                if (!(rawMessage is SocketUserMessage message))
                {
                    return;                                                      //Message not from user, or some form of error
                }
                SocketGuild guild = ((SocketGuildChannel)message.Channel).Guild; //Gets the server
                defaultChannel = guild.DefaultChannel;                           //Default Channel

                //Listen for any praising
                if (message.Content.Contains("praisesun") || message.Content.Contains("<:praisesun:372813946052280341>") && !(message.Content.Contains("STOP")))   //Listen for praise sun stuff
                {
                    await message.Channel.SendMessageAsync("<:praisesun:372813946052280341><:praisesun:372813946052280341><:praisesun:372813946052280341><:praisesun:372813946052280341><:praisesun:372813946052280341>\n" +
                                                           "<:praisesun:372813946052280341><:praisesun:372813946052280341><:praisesun:372813946052280341><:praisesun:372813946052280341><:praisesun:372813946052280341>\n" +
                                                           "<:praisesun:372813946052280341><:praisesun:372813946052280341><:praisesun:372813946052280341><:praisesun:372813946052280341><:praisesun:372813946052280341>\n");
                }

                var argPos = 0; //Set argPos for use
                if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos)))
                {
                    return;
                }

                var context = new CommandContext(client, message);
                var result  = await commandService.ExecuteAsync(context, argPos, serviceProvider);

                if (!result.IsSuccess) //Error Logging
                {
                    Console.WriteLine("Failed to run command: {0}", result.ErrorReason);
                }
            };

            var token = File.ReadAllText(Path);            //Reads the bots token so it can connect
            await client.LoginAsync(TokenType.Bot, token); //Logs bot in

            await client.StartAsync();                     //Starts bot

            client.Ready += async() => {                   //Bot is ready, send duke nukem quote Random quote between 0-4
                String messageToAnnoy = loginQuotes[randomQuote.Next(0, 4)];
                await defaultChannel.SendMessageAsync(messageToAnnoy);

                //await message.Channel.SendMessageAsync(messageToAnnoy);
            };
            await Task.Delay(-1); //Keeps bot running
        }
Example #19
0
        private static async Task MessageReceived(SocketMessage messageParam)
        {
            if (!(messageParam is SocketUserMessage message))
            {
                return;
            }                                                             // If the message is null, return.
            if (message.Author.IsBot)
            {
                return;
            }                                     // If the message was posted by a BOT account, return.
            if (message.Author.IsUserIgnoredByBot() && message.Author.Id != Configuration.Load().Developer)
            {
                return;
            }                                                                                                           // If the bot is ignoring the user AND the user NOT Melissa.

            // If the message came from somewhere that is not a text channel -> Private Message
            if (!(messageParam.Channel is ITextChannel))
            {
                EmbedFooterBuilder efb = new EmbedFooterBuilder()
                                         .WithText("UID: " + message.Author.Id + " | MID: " + message.Id);
                EmbedBuilder eb = new EmbedBuilder()
                                  .WithTitle("Private Message - Posted By: @" + message.Author.Username + "#" + message.Author.Discriminator)
                                  .WithDescription(message.Content)
                                  .WithFooter(efb)
                                  .WithCurrentTimestamp();

                await Configuration.Load().LogChannelId.GetTextChannel().SendMessageAsync("", false, eb.Build());

                return;
            }

            await new LogMessage(LogSeverity.Info, "MessageReceived", "[" + messageParam.Channel.GetGuild().Name + "/#" + messageParam.Channel.Name + "] " + "[@" +
                                 messageParam.Author.Username + "] : " + messageParam.Content).PrintToConsole();

            var uPrefix = message.Author.GetCustomPrefix();
            var gPrefix = Guild.Load(message.Channel.GetGuild().Id).Prefix;

            if (string.IsNullOrEmpty(uPrefix))
            {
                uPrefix = gPrefix;
            }                                                         // Fixes an issue with users not receiving coins due to null prefix.
            var argPos = 0;

            if (message.HasStringPrefix(gPrefix, ref argPos) ||
                message.HasMentionPrefix(Bot.CurrentUser, ref argPos) ||
                message.HasStringPrefix(uPrefix, ref argPos))
            {
                var context = new SocketCommandContext(Bot, message);
                var result  = await _commandService.ExecuteAsync(context, argPos, _serviceProvider);

                if (!result.IsSuccess && Configuration.Load().UnknownCommandEnabled)
                {
                    var errorMessage = await context.Channel.SendMessageAsync(messageParam.Author.Mention + ", " + result.ErrorReason);

                    await new LogMessage(LogSeverity.Error, "MessageReceived", message.Author.Username + " - " + result.ErrorReason).PrintToConsole();

                    errorMessage.DeleteAfter(20);
                }
            }
            else if (message.Content.ToUpper() == "F") // If the message is just "F", pay respects.
            {
                var respects = Configuration.Load().Respects + 1;
                Configuration.UpdateConfiguration(respects: respects);

                var eb = new EmbedBuilder()
                         .WithDescription("**" + message.Author.Username + "** has paid their respects.")
                         .WithFooter("Total Respects: " + respects)
                         .WithColor(message.Author.GetCustomRGB());

                await message.Channel.SendMessageAsync("", false, eb.Build());
            }
            else
            {
                if (Configuration.Load().AwardingEXPEnabled)
                {
                    if (message.Content.Length >= Configuration.Load().MinLengthForEXP)
                    {
                        if (Channel.Load(message.Channel.Id).AwardingEXP)
                        {
                            message.Author.AwardEXPToUser(message.Channel.GetGuild());
                        }
                    }
                }
            }
        }