Пример #1
0
        public async Task SetInterest(double rate)
        {
            SocketGuildUser checkUser = Context.User as SocketGuildUser;

            if (!checkUser.GuildPermissions.Administrator)
            {
                await Context.Channel.SendMessageAsync($"Only an administrator can set the interest rate.");

                return;
            }

            try
            {
                await Data.Data.SetInterest(Context.Guild.Id, Context.Guild.Name, (int)rate);
            }
            catch (Exception)
            {
                await Context.Channel.SendMessageAsync("Please make sure the interest rate is in whole value format, 5% would be \"!setinterest 5\".");

                return;
            }
            await Context.Channel.SendMessageAsync($"Interest rate has been set to {rate}%.");

            //Channel to send the mod logs in
            await ModLog.PostInModLog(Context.Guild, $"Set interest rate to {rate}%", Context.User, null, "");
        }
Пример #2
0
        public async Task SetModLogChannel(IGuildChannel channel)
        {
            SocketGuildUser checkUser = Context.User as SocketGuildUser;

            if (!checkUser.GuildPermissions.Administrator)
            {
                await Context.Channel.SendMessageAsync($"Only an administrator can set the mod log channel.");

                return;
            }

            //Set the channel
            await Data.Data.SetModLogChannel(Context.Guild.Id, channel.Id, Context.Guild.Name);

            //Send a test message
            SocketUser Nephry = Context.Guild.GetUser(322806920203337740);

            try
            {
                await ModLog.PostInModLog(Context.Guild, "Test", Nephry, null, "Testing");
            }
            catch (Exception)
            {
                await Data.Data.SetModLogChannel(Context.Guild.Id, 0, Context.Guild.Name);

                return;
            }
            await Context.Channel.SendMessageAsync($"Mod log channel successfully set to \"{channel.Name}\"");

            //Channel to send the mod logs in
            await ModLog.PostInModLog(Context.Guild, "Set the mod log channel to: " + channel.Name, Context.User, null, "");
        }
Пример #3
0
        public async Task Reset(IUser target = null, string reason = "No reason provided.")
        {
            SocketGuildUser User1 = Context.User as SocketGuildUser;

            if (!User1.GuildPermissions.Administrator) //Make sure user issuing command is admin
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you don't have administrator permissions in this discord server! Ask a administrator or the owner to execute this command!");

                return;
            }

            if (target == null) //Make sure a user was pinged
            {
                await Context.Channel.SendMessageAsync($"You need to tell me which user you want to reset the gold of! For example: !gold reset {Context.User.Mention}");

                return;
            }

            if (target.IsBot) //Make sure pinged user isn't a bot
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, bots can't use gold, so you also can't reset the progress of bots! :robot:");

                return;
            }
            await Context.Channel.SendMessageAsync($"{target.Mention}, you have been reset by {Context.User.Mention}! This means you have lost all your gold!");

            await ModLog.PostInModLog(Context.Guild, "Reset Gold", Context.User, target as IGuildUser, reason);

            //Remove the gold
            using (SqliteDbContext DBContext = new SqliteDbContext())
            {
                DBContext.Gold.RemoveRange(DBContext.Gold.Where(x => x.UserId == target.Id && x.Serverid == Context.Guild.Id));
                await DBContext.SaveChangesAsync();
            }
        }
Пример #4
0
        public async Task Take(IUser target = null, int Amount = 0, string reason = "No reason provided.")
        {
            //Make sure the command issuer is an administrator
            SocketGuildUser User1 = Context.User as SocketGuildUser;

            if (!User1.GuildPermissions.Administrator)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you don't have administrator permissions in this discord server! Ask a moderator or the owner to execute this command!");

                return;
            }

            //Make sure a user was pinged
            if (target == null)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you didn't mention a user to give the gold to! Please use this syntax: !gold give @user amount reason");

                return;
            }

            //Make sure the user pinged is not a bot
            if (target.IsBot)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, bots can't use gold, so you can't give gold to a bot!");

                return;
            }

            //Make sure an amount is specified
            if (Amount == 0)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you need to specify a valid amount of gold that I need to give to {target.Mention}");

                return;
            }

            //Make sure the value is above 0
            if (Amount > 0)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you can only take a positive value in gold.");

                return;
            }

            //Make sure the user has enough gold to take
            if (Amount > Data.Data.GetGold(target.Id, Context.Guild.Id))
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, {target.Mention} does not have that much gold!" +
                                                       $" If you want to take all of their gold use the !reset command.");

                return;
            }

            await Context.Channel.SendMessageAsync($"tada: {Context.User.Mention} you have taken {Amount} gold from {target.Mention}!");

            //Take gold away and post admin action in mod log
            await Data.Data.SaveGoldMinus(target.Id, Amount, Context.Guild.Id, target.Username);

            await ModLog.PostInModLog(Context.Guild, "Took Gold", Context.User, target as IGuildUser, reason);
        }
Пример #5
0
        public async Task AdminGive(IUser target = null, int Amount = 0, string reason = "No reason provided.")
        {
            //Make sure someone was targeted
            if (target == null)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you didn't mention a user to give the gold to! Please use this syntax: !gold give @user amount reason");

                return;
            }

            //At this point, we made sure that a user has been pinged
            if (target.IsBot)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, bots can't use gold, so you can't give gold to a bot!");

                return;
            }

            //At this point we made sure a user has been pinged AND that the user is not a bot
            if (Amount == 0)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you need to specify a valid amount of gold that I need to give to {target.Mention}");

                return;
            }

            //Make sure the value is above 0
            if (Amount < 1)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you can only give a positive value in gold.");

                return;
            }

            //At this point, we made sure a user has been pinged, that the user is not a bot AND that there is a valid amount of coins
            SocketGuildUser User1 = Context.User as SocketGuildUser;

            if (!User1.GuildPermissions.Administrator)
            {
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you don't have administrator permissions in this discord server!");

                return;
            }

            await Data.Data.SaveGold(target.Id, Amount, Context.Guild.Id, target.Username);

            await ModLog.PostInModLog(Context.Guild, "Gave Gold", Context.User, target as IGuildUser, reason);

            await Context.Channel.SendMessageAsync($"tada: {target.Mention} you have received {Amount} gold from {Context.User.Mention}!");
        }
Пример #6
0
        public async Task SetWelcomeMessage([Remainder] string message)
        {
            SocketGuildUser checkUser = Context.User as SocketGuildUser;

            if (!checkUser.GuildPermissions.Administrator)
            {
                await Context.Channel.SendMessageAsync($"Only an administrator can set the welcome message.");

                return;
            }

            await Data.Data.SetWelcomeMessage(Context.Guild.Id, message, Context.Guild.Name);

            await Context.Channel.SendMessageAsync($"Welcome message set to \"{message}\".");

            //Channel to send the mod logs in
            await ModLog.PostInModLog(Context.Guild, $"Set the welcome message to: \"{message}\"", Context.User, null, "");
        }
Пример #7
0
        public async Task NoBotSpamChannel()
        {
            SocketGuildUser checkUser = Context.User as SocketGuildUser;

            if (!checkUser.GuildPermissions.Administrator)
            {
                await Context.Channel.SendMessageAsync($"Only an administrator can free the bot.");

                return;
            }

            await Data.Data.SetBotSpamChannel(Context.Guild.Id, 0, Context.Guild.Name);

            await Context.Channel.SendMessageAsync($"I can now respond freely in all channels.");

            //Channel to send the mod logs in
            await ModLog.PostInModLog(Context.Guild, "Freed the bot.", Context.User, null, "");
        }
Пример #8
0
        public async Task StopModLog()
        {
            SocketGuildUser checkUser = Context.User as SocketGuildUser;

            if (!checkUser.GuildPermissions.Administrator)
            {
                await Context.Channel.SendMessageAsync($"Only an administrator can stop the bot from posting in the mod log channel.");

                return;
            }

            await Data.Data.SetModLogChannel(Context.Guild.Id, 0, Context.Guild.Name);

            await Context.Channel.SendMessageAsync($"{Context.User.Mention}, I will stop posting mod logs now!");

            //Channel to send the mod logs in
            await ModLog.PostInModLog(Context.Guild, "Stopped the mod log channel.", Context.User, null, "");
        }
Пример #9
0
        public async Task SetBotSpamChannel(IGuildChannel channel)
        {
            SocketGuildUser checkUser = Context.User as SocketGuildUser;

            if (!checkUser.GuildPermissions.Administrator)
            {
                await Context.Channel.SendMessageAsync($"Only an administrator can set the bot spam channel.");

                return;
            }

            //Set the channel
            await Data.Data.SetBotSpamChannel(Context.Guild.Id, channel.Id, Context.Guild.Name);

            await Context.Channel.SendMessageAsync($"Bot spam channel successful set to \"{channel.Name}\"");

            //Channel to send the mod logs in
            await ModLog.PostInModLog(Context.Guild, "Set the bot spam channel to: " + channel.Name, Context.User, null, "");
        }
Пример #10
0
        public async Task SetChatLogChannel(IGuildChannel channel)
        {
            SocketGuildUser checkUser = Context.User as SocketGuildUser;

            if (!checkUser.GuildPermissions.Administrator)
            {
                await Context.Channel.SendMessageAsync($"Only an administrator can set the chat log channel.");

                return;
            }

            await Data.Data.SetChatLogChannel(Context.Guild.Id, channel.Id, Context.Guild.Name);

            //Send a test message
            ulong channelToSendMessageTo                   = Data.Data.GetChatLogChannel(Context.Guild.Id);
            SocketGuildChannel    channelToGet             = Context.Guild.GetChannel(channelToSendMessageTo);
            ISocketMessageChannel channelToSendTestMessage = channelToGet as ISocketMessageChannel;

            try
            {
                await channelToSendTestMessage.SendMessageAsync("Test.");
            }
            catch (Exception)
            {
                await Context.Channel.SendMessageAsync($"I cannot send messages to the chat log channel. " +
                                                       $"Please make sure I have permissions to send messages in <#{channel.Id}> then try again.");

                await Data.Data.SetChatLogChannel(Context.Guild.Id, 0, Context.Guild.Name);

                return;
            }


            await Context.Channel.SendMessageAsync($"Chat log channel successfully set to <#{channel.Id}>");

            //Channel to send the mod logs in
            await ModLog.PostInModLog(Context.Guild, $"Set the chat log channel to: <#{channel.Id}>", Context.User, null, "");
        }
Пример #11
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);
            }
        }