Beispiel #1
0
        public static async void Unmute(string moderator, ITextChannel channel, SocketGuildUser user)
        {
            foreach (SocketTextChannel chan in user.Guild.TextChannels)
            {
                var guild = user.Guild;
                //Don't mess with channel permissions if nonmembers can't speak there anyway
                if (IsPublicChannel(chan))
                {
                    try
                    {
                        await chan.RemovePermissionOverwriteAsync(user, RequestOptions.Default);
                    }
                    catch
                    {
                        Processing.LogConsoleText($"Failed to unmute in {guild.Name}#{chan.Name.ToString()}", guild.Id);
                    }
                }
            }

            var embed = Embeds.Unmute(user);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            //Log the unmute in the bot-logs channel
            embed = Embeds.LogUnmute(moderator, channel, user);
            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(user.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Beispiel #2
0
        //Grant a user a role if they type the password in the verification channel
        public static async Task VerificationCheck(SocketMessage message)
        {
            var user  = (IGuildUser)message.Author;
            var guild = user.Guild;

            if (Setup.IsVerificationChannel((IGuildChannel)message.Channel))
            {
                if (message.Content.ToLower() == UserSettings.Verification.VerificationMessage(guild.Id).ToLower())
                {
                    await message.DeleteAsync();

                    ulong memberRoleId = UserSettings.Verification.MemberRoleID(guild.Id);
                    if (memberRoleId != 0)
                    {
                        var memberRole = user.Guild.GetRole(memberRoleId);
                        await user.AddRoleAsync(memberRole);

                        var embed  = Embeds.LogMemberAdd(user);
                        var user2  = (SocketGuildUser)user;
                        var botlog = (ITextChannel)user2.Guild.GetChannel(UserSettings.Channels.BotLogsId(user.Guild.Id));
                        await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
                    }
                    else
                    {
                        await message.Channel.SendMessageAsync("Attempted to give the new member a role, but it has to be configured first!");
                    }
                }
                else
                {
                    await message.DeleteAsync();
                }
            }
        }
Beispiel #3
0
        public static async void Unlock(SocketGuildUser moderator, ITextChannel channel)
        {
            //Unlock the channel
            var guild = channel.Guild;

            //Don't mess with channel permissions if nonmembers can't speak there anyway
            if (IsPublicChannel((SocketGuildChannel)channel))
            {
                try
                {
                    await channel.RemovePermissionOverwriteAsync(guild.EveryoneRole, RequestOptions.Default);
                }
                catch
                {
                    Processing.LogConsoleText($"Failed to unlock {guild.Name}#{channel.Name.ToString()}", guild.Id);
                }
            }

            //Announce the unlock
            var embed = Embeds.Unlock(channel);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            //Log the lock in the bot-logs channel
            embed = Embeds.LogUnlock(moderator, channel);
            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(channel.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Beispiel #4
0
        public async Task Invite()
        {
            var user = (SocketGuildUser)Context.Message.Author;

            if (Xml.CommandAllowed("invite", Context) && user.Roles.Count > 1 && !user.Roles.Any(x => x.Id.Equals(UserSettings.Roles.LurkerRoleID(Context.Guild.Id))))
            {
                //Create and link Invite
                var     guildChan = (SocketTextChannel)Context.Channel;
                IInvite invite    = await guildChan.CreateInviteAsync(86400, 1, true, true);

                IUserMessage msg = await Context.Channel.SendMessageAsync($"Your new invite link is ``{invite.Url}`` and it will expire in 24 hours. This message will be deleted in 7 seconds.");

                //Log which user created invite
                var botlog = await Context.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(Context.Guild.Id));

                var embed = Embeds.LogCreateInvite((SocketGuildUser)Context.Message.Author, invite.Id);
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);

                //Save Invite and Author UserID to XML doc to track
                var invites = Context.Guild.GetInvitesAsync().Result;
                JackFrostBot.UserSettings.Invites.Update(Context.Guild.Id, invites);
                //Delete message after 15 seconds
                await Task.Delay(TimeSpan.FromSeconds(7)).ContinueWith(__ => msg.DeleteAsync());
            }
        }
Beispiel #5
0
        public async Task Award([Summary("The user to award.")] SocketGuildUser mention, [Summary("The amount to award."), Remainder] int amount = 1)
        {
            var botlog = await Context.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(Context.Guild.Id));

            if (Xml.CommandAllowed("award", Context))
            {
                await Context.Message.DeleteAsync();

                if (amount > 10)
                {
                    await Context.Channel.SendMessageAsync("That's too much to award! Try a smaller amount.");
                }
                else if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
                {
                    UserSettings.Currency.Add(Context.Guild.Id, mention.Id, amount);
                    var embed = Embeds.LogAward((SocketGuildUser)Context.Message.Author, mention.Username, amount);
                    await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);

                    embed = Embeds.Award((SocketGuildUser)Context.Message.Author, mention.Username, amount);
                    await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
Beispiel #6
0
        public async Task PinMessage([Summary("The ID of the message to pin.")] string messageId, [Remainder, Summary("The ID of the channel the message is in.")] IMessageChannel channel)
        {
            List <ulong> allowedChannels = new List <ulong>()
            {
                681270126657798295, 681273506964701222, 143149937247387649, 448202199852646431
            };

            if (Xml.CommandAllowed("pin", Context) && allowedChannels.Contains(channel.Id))
            {
                if (channel == null)
                {
                    channel = (ITextChannel)Context.Channel;
                }
                var msg = await channel.GetMessageAsync(Convert.ToUInt64(messageId));

                try
                {
                    var pinChannel = await Context.Guild.GetTextChannelAsync(JackFrostBot.UserSettings.Channels.PinsChannelId(Context.Guild.Id));

                    var embed = Embeds.Pin((IGuildChannel)Context.Channel, msg, Context.Message.Author);
                    await pinChannel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
                }
                catch
                {
                    await Context.Channel.SendMessageAsync("Could not find referenced message in the specified channel.");
                }
            }
        }
Beispiel #7
0
        public static async void PruneLurkers(SocketGuildUser moderator, ITextChannel channel, IReadOnlyCollection <IGuildUser> users)
        {
            int usersPruned = 0;

            foreach (IGuildUser user in users)
            {
                if (user.RoleIds.Any(x => x == UserSettings.Roles.LurkerRoleID(channel.Guild.Id)))
                {
                    Console.WriteLine($"Lurker found: {user.Username}");
                    await user.KickAsync("Inactivity");

                    usersPruned++;
                }
            }

            var embed = Embeds.PruneLurkers(usersPruned);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            //Log the unmute in the bot-logs channel
            embed = Embeds.LogPruneLurkers(moderator, usersPruned);
            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(channel.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Beispiel #8
0
        public static async void PruneNonmembers(SocketGuildUser moderator, ITextChannel channel, IReadOnlyCollection <IGuildUser> users)
        {
            int usersPruned = 0;

            foreach (IGuildUser user in users)
            {
                if (user.RoleIds.Count <= 1)
                {
                    Processing.LogConsoleText($"Nonmember found: {user.Username}", channel.Guild.Id);
                    await user.KickAsync("Inactivity");

                    usersPruned++;
                }
            }

            var embed = Embeds.PruneNonmembers(usersPruned);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            //Log the prune in the bot-logs channel
            embed = Embeds.LogPruneNonmembers(moderator, usersPruned);
            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(channel.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Beispiel #9
0
 public async Task GetInfo([Remainder, Summary("The format to get info about.")] string keyword)
 {
     if (Xml.CommandAllowed("about", Context))
     {
         var embed = Embeds.FormatInfo(keyword, Context.Guild.Id);
         await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
     }
 }
Beispiel #10
0
 public async Task ShowMsgInfo()
 {
     if (Xml.CommandAllowed("show msginfo", Context))
     {
         var embed = Embeds.ShowMsgInfo(Context.Guild.Id);
         await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
     }
 }
Beispiel #11
0
 public async Task ShowWarns([Summary("The user whose warns to show.")] SocketGuildUser mention = null)
 {
     if (Xml.CommandAllowed("show warns", Context))
     {
         var embed = Embeds.ShowWarns((IGuildChannel)Context.Channel, mention);
         await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
     }
 }
Beispiel #12
0
 public async Task List()
 {
     if (Xml.CommandAllowed("list", Context))
     {
         var embed = Embeds.Keywords(Context.Guild.Id);
         await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
     }
 }
Beispiel #13
0
 public async Task GetHelp()
 {
     if (Xml.CommandAllowed("help", Context))
     {
         var embed = Embeds.Help(Context.Guild.Id, Moderation.IsModerator((IGuildUser)Context.Message.Author));
         await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
     }
 }
Beispiel #14
0
        public static async void ClearWarns(SocketGuildUser moderator, ITextChannel channel, SocketGuildUser user)
        {
            //Announce clearing of warns in both channel and bot-logs
            var embed = Embeds.ClearWarns(moderator, channel, user);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(user.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }

            //Clear warns from this user
            UserSettings.Warns.Clear(channel.Guild.Id, user.Id);
        }
Beispiel #15
0
        public static async void Warn(string moderator, ITextChannel channel, SocketGuildUser user, string reason)
        {
            reason = $"({user.Username}#{user.Discriminator}) {reason}";
            //Warn User
            var embed = Embeds.Warn(user, reason);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            //Log the warn in bot-logs
            embed = Embeds.LogWarn(moderator, channel, user, reason);
            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(user.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }

            //Write the userid and reason in warns.xml
            UserSettings.Warns.Add(user.Guild.Id, user.Id, reason);

            //Measure # of warns the user now has
            int warns = WarnLevel(user);

            //Mute, kick or ban a user if they've accumulated too many warns
            int muteLevel = UserSettings.BotOptions.MuteLevel(user.Guild.Id);
            int kickLevel = UserSettings.BotOptions.KickLevel(user.Guild.Id);
            int banLevel  = UserSettings.BotOptions.BanLevel(user.Guild.Id);

            if (warns > 0)
            {
                await channel.SendMessageAsync($"{user.Username} has been warned {warns} times.");

                if (warns >= banLevel)
                {
                    Ban(user.Guild.CurrentUser.Username, channel, user,
                        "User was automatically banned for accumulating too many warnings.");
                }
                else if (warns >= kickLevel)
                {
                    Kick(user.Guild.CurrentUser.Username, channel, user,
                         "User was automatically kicked for accumulating too many warnings.");
                }
                else if (warns >= muteLevel)
                {
                    Mute(user.Guild.CurrentUser.Username, channel, user);
                }
            }
        }
Beispiel #16
0
        public async Task ShowColors()
        {
            if (Xml.CommandAllowed("show colors", Context))
            {
                List <string> colorRoleNames = new List <string>();

                foreach (var role in Context.Guild.Roles)
                {
                    if (role.Name.Contains("Color: "))
                    {
                        colorRoleNames.Add(role.Name);
                    }
                }

                var embed = Embeds.ShowColors((IGuildChannel)Context.Channel, colorRoleNames, Context.Guild.Id);
                await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Beispiel #17
0
        public async Task PinMessage([Remainder, Summary("The ID of the message to pin.")] string messageId)
        {
            if (Xml.CommandAllowed("pin", Context))
            {
                var channel = (ITextChannel)Context.Channel;
                var msg     = await channel.GetMessageAsync(Convert.ToUInt64(messageId));

                try
                {
                    var pinChannel = await Context.Guild.GetTextChannelAsync(JackFrostBot.UserSettings.Channels.PinsChannelId(Context.Guild.Id));

                    var embed = Embeds.Pin((IGuildChannel)Context.Channel, msg);
                    await pinChannel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
                }
                catch
                {
                    await Context.Channel.SendMessageAsync("Could not find referenced message in this channel.");
                }
            }
        }
Beispiel #18
0
        public static async void ClearWarn(SocketGuildUser moderator, ITextChannel channel, int index, SocketGuildUser user)
        {
            //Get warn userId and description
            Tuple <string, string> tuple = UserSettings.Warns.Get(channel.Guild.Id, index);
            string removedWarn           = tuple.Item1 + " " + tuple.Item2;

            //Announce clearing of warns in both channel and bot-logs
            var embed = Embeds.ClearWarn(moderator, removedWarn);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(moderator.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }

            //Write new warns list to file
            UserSettings.Warns.Remove(channel.Guild.Id, index);
        }
Beispiel #19
0
        public async Task Send([Summary("The user to send currency to.")] SocketGuildUser mention = null, [Summary("The amount to send."), Remainder] int amount = 1)
        {
            if (Xml.CommandAllowed("send", Context))
            {
                //Check that the post author has money
                bool hasMoney       = false;
                int  originalAmount = 0;
                foreach (var pair in UserSettings.Currency.Get(Context.Guild.Id))
                {
                    if (pair.Item1 == Context.Message.Author.Id.ToString())
                    {
                        originalAmount = pair.Item2;
                    }
                }

                if (originalAmount >= amount)
                {
                    hasMoney = true;
                }


                if (hasMoney)
                {
                    UserSettings.Currency.Remove(Context.Guild.Id, Context.Message.Author.Id, amount);
                    UserSettings.Currency.Add(Context.Guild.Id, mention.Id, amount);

                    var botlog = await Context.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(Context.Guild.Id));

                    var embed = Embeds.Send((SocketGuildUser)Context.Message.Author, mention.Username, amount);
                    await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);

                    await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
                }
                else
                {
                    await Context.Channel.SendMessageAsync($"You don't have enough {UserSettings.BotOptions.GetString("CurrencyName", Context.Guild.Id)}!");
                }
            }
        }
Beispiel #20
0
        //Write info on the last deleted message to a txt file
        public static async Task LogDeletedMessage(SocketMessage message, string reason)
        {
            var user  = (IGuildUser)message.Author;
            var guild = user.Guild;

            //Create txt if it doesn't exist
            string logPath = $"Servers//{guild.Id}//LastDeletedMsg.txt";

            if (!File.Exists(logPath))
            {
                File.Create(logPath);
            }

            LogConsoleText(reason, guild.Id);
            await message.DeleteAsync();

            File.WriteAllText(logPath, $"**Author**: {user.Username} ({user.Id})\n**Time**: {message.Timestamp}\n**Reason**: {reason}");

            //Announce message deletion
            var botlog = (SocketTextChannel)user.Guild.GetChannelAsync(JackFrostBot.UserSettings.Channels.BotLogsId(user.Guild.Id)).Result;
            var embed  = Embeds.ShowMsgInfo(guild.Id);
            await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
        }
Beispiel #21
0
        public async Task Redeem([Summary("The user to take from.")] SocketGuildUser mention, [Summary("The amount to take."), Remainder] int amount = 1)
        {
            var botlog = await Context.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(Context.Guild.Id));

            if (Xml.CommandAllowed("redeem", Context))
            {
                await Context.Message.DeleteAsync();

                if (Moderation.IsModerator((IGuildUser)Context.Message.Author))
                {
                    UserSettings.Currency.Remove(Context.Guild.Id, mention.Id, amount);
                    var embed = Embeds.LogRedeem((SocketGuildUser)Context.Message.Author, mention.Username, amount);
                    await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);

                    embed = Embeds.Redeem((SocketGuildUser)Context.Message.Author, mention.Username, amount);
                    await Context.Channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);
                }
                else
                {
                    await Context.Channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", Context.Guild.Id));
                }
            }
        }
Beispiel #22
0
        public static async void Mute(string moderator, ITextChannel channel, SocketGuildUser user)
        {
            var guild = user.Guild;

            //Mute the specified user in each text channel if it's not a bot
            if (!user.IsBot)
            {
                foreach (SocketTextChannel chan in user.Guild.TextChannels)
                {
                    //Don't mess with channel permissions if nonmembers can't speak there anyway
                    if (IsPublicChannel(chan))
                    {
                        try
                        {
                            await chan.AddPermissionOverwriteAsync(user, new OverwritePermissions(sendMessages : PermValue.Deny, addReactions : PermValue.Deny), RequestOptions.Default);
                        }
                        catch
                        {
                            Processing.LogConsoleText($"Failed to mute in {guild.Name}#{chan.Name.ToString()}", guild.Id);
                        }
                    }
                }
            }

            //Announce the mute
            var embed = Embeds.Mute(user);
            await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

            //Log the mute in the bot-logs channel
            embed = Embeds.LogMute(moderator, channel, user);
            var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(user.Guild.Id));

            if (botlog != null)
            {
                await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Beispiel #23
0
        public static async void Ban(string moderator, ITextChannel channel, SocketGuildUser user, string reason)
        {
            try {
                //Ban user
                await user.Guild.AddBanAsync((IUser)user, 0, reason);

                //Announce ban in channel where infraction occured
                var embed = Embeds.Ban(user, reason);
                await channel.SendMessageAsync("", embed : embed).ConfigureAwait(false);

                //Log ban in bot-logs
                embed = Embeds.LogBan(moderator, channel, user, reason);
                var botlog = await channel.Guild.GetTextChannelAsync(UserSettings.Channels.BotLogsId(user.Guild.Id));

                if (botlog != null)
                {
                    await botlog.SendMessageAsync("", embed : embed).ConfigureAwait(false);
                }
            }
            catch
            {
                await channel.SendMessageAsync(UserSettings.BotOptions.GetString("NoPermissionMessage", channel.Guild.Id));
            }
        }