Ejemplo n.º 1
0
        public async Task Ban(IGuildUser user, [Remainder] string msg = null)
        {
            if (string.IsNullOrWhiteSpace(msg))
            {
                msg = "❗️No reason provided.";
            }
            if (Context.User.Id != user.Guild.OwnerId && ((IGuildUser)Context.User).GetRoles().Select(r => r.Position).Max() >= ((IGuildUser)Context.User).GetRoles().Select(r => r.Position).Max())
            {
                await Context.Channel.SendErrorAsync("⚠️ You can't use this command on users with a role higher or equal to yours in the role hierarchy.").ConfigureAwait(false);

                return;
            }
            try
            {
                await(await user.CreateDMChannelAsync()).SendErrorAsync($"⛔️ **You have been BANNED from `{Context.Guild.Name}` server.**\n" +
                                                                        $"⚖ *Reason:* {msg}").ConfigureAwait(false);
                await Task.Delay(2000).ConfigureAwait(false);
            }
            catch { }
            try
            {
                await Context.Guild.AddBanAsync(user, 7).ConfigureAwait(false);

                await Context.Channel.SendConfirmAsync("⛔️ **Banned** user **" + user.Username + "** ID: `" + user.Id + "`").ConfigureAwait(false);
            }
            catch
            {
                await Context.Channel.SendErrorAsync("⚠️ **Error.** Most likely I don't have sufficient permissions.").ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
        public async Task Ban([Summary("User to ban")] IGuildUser target, [Remainder] string reason = null)
        {
            if (target.Id == Context.Message.Author.Id)
            {
                await Context.Message.AddReactionAsync(new Emoji("⛔"));
                await ReplyAsync($":no_entry_sign: `{StringResourceHandler.GetTextStatic("Moderation", "cannotBanSelf")}`").ConfigureAwait(false);

                return;
            }
            try
            {
                var userdm = await target.CreateDMChannelAsync();

                var dmembed = new EmbedBuilder()
                              .WithColor(Color.Red)
                              .WithTitle(StringResourceHandler.GetTextStatic("Moderation", "dm_reason"))
                              .WithDescription(reason ?? StringResourceHandler.GetTextStatic("Moderation", "dm_NoReasonSpecified"))
                              .WithFooter($"{StringResourceHandler.GetTextStatic("Moderation", "dm_by", StringResourceHandler.GetTextStatic("Moderation", "dm_banned"))} @{Context.User.Username}#{Context.User.Discriminator}")
                              .Build();
                await userdm.SendMessageAsync($":anger: {StringResourceHandler.GetTextStatic("Moderation", "dm_ban_header", Context.Guild.Name)}", false, dmembed);
            }
            catch (Exception e)
            {
                await ReplyAsync(":no_entry_sign: " + StringResourceHandler.GetTextStatic("Moderation", "DMFailed", e.Message));
            }
            await Context.Message.AddReactionAsync(new Emoji("🔨"));

            await Context.Guild.AddBanAsync(target, 0, reason).ConfigureAwait(false);

            await ReplyAsync($":hammer: `{StringResourceHandler.GetTextStatic("Moderation", "ban", $"@{target.Username}#{target.Discriminator}")}`").ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        public async Task BanAsync([Summary("The user to ban")] IGuildUser target, [Summary("The reason for one such ban")] string reason)
        {
            IDMChannel dmchannel = await target.CreateDMChannelAsync();                                                                         //  Stores a dmchannel with the target

            ITextChannel logchannel = await Context.Guild.GetTextChannelAsync(246572485292720139) as ITextChannel;                              //  Gets the logchannel, then stores it

            if (!string.IsNullOrWhiteSpace(reason))                                                                                             //  Checks to see if the input parameter 'reason' is null or whitespace
            {
                await Context.Channel.SendMessageAsync(
                    $"Banned user: {target}.\n" +                                                                                               //  Sends the banned user to the channel
                    $"Reason: {reason}");                                                                                                       //  Sends the reason the channel

                await dmchannel.SendMessageAsync($"You have been banned from {target.Guild.ToString()}.");                                      //  Sends text to the dmchannel

                await dmchannel.SendMessageAsync($"Reason: {reason}.");                                                                         //  Sends text to the dmchannel

                await dmchannel.SendMessageAsync($"If you would like to appeal this ban, send a message to: {Context.User.Mention}.");          //  Sends text to the dmchannel

                await dmchannel.SendMessageAsync(Format.Italics("this is an automated message."));                                              //  Sends text to the dmchannel

                await logchannel.SendMessageAsync($"USER: {target} ID: {target.Id} has been BANNED.\nREASON: {reason}.");                       //  Sends text to the logchannel
            }
            try
            {
                await Context.Guild.AddBanAsync(target);                                                                                        //  Tries to add the target to the server's ban list
            }
            catch
            {
                await Context.Channel.SendMessageAsync("Error. Most likely I don't have sufficient permissions");                               //  If the ban fails it will send this text to the channel
            }
        }
Ejemplo n.º 4
0
        public async Task KickAsync([Summary("The user to kick.")] IGuildUser target, [Optional] string reason)
        {
            IDMChannel dmchannel = await target.CreateDMChannelAsync();                                                                         //  Stores a dmchannel with the target

            ITextChannel logchannel = await Context.Guild.GetTextChannelAsync(246572485292720139) as ITextChannel;                              //  Stores the logchannel

            await dmchannel.SendMessageAsync($"You have been kicked from {target.Guild.ToString()}.");                                          //  Sends a message in the dmchannel

            await logchannel.SendMessageAsync($"USER: {target} ID: {target.Id} has been KICKED.");                                              //  Sends text to the logchannel


            if (!string.IsNullOrWhiteSpace(reason))                                                                                             //  Checks to see if the input parameter 'reason' is null or whitespace
            {
                await dmchannel.SendMessageAsync($"Reason: {reason}.");                                                                         //  Sends the reason parameter to the dmchannel

                await logchannel.SendMessageAsync($"REASON: {reason}.");                                                                        //  Sends the reason parameter to the logchannel
            }

            await dmchannel.SendMessageAsync($"If you would like to appeal this kick, send a message to: {Context.User.Mention}.");             //  Sends text to the dmchannel

            await dmchannel.SendMessageAsync(Format.Italics("this is an automated message."));                                                  //  Sends text to the dmchannel in the italics format


            await target.KickAsync();                                                                                                           //  Calls the KickAsync function on the target

            await Context.Channel.SendMessageAsync($"Kicked user: {target}.");                                                                  //  Sends a message to the channel to say that the user has been kicked

            await Context.Channel.SendFileAsync("Gifs/Admin_Kicks_User.gif");                                                                   //  Sends a gif to the channel
        }
Ejemplo n.º 5
0
            private static Task UserJoined(IGuildUser user)
            {
                var joinedTask = Task.Run(async() =>
                {
                    try
                    {
                        GuildConfig conf;
                        using (var uow = DbHandler.UnitOfWork())
                        {
                            conf = uow.GuildConfigs.For(user.Guild.Id, set => set);
                        }

                        if (conf.SendChannelGreetMessage)
                        {
                            var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.GreetMessageChannelId);
                            if (channel != null) //maybe warn the server owner that the channel is missing
                            {
                                var msg = conf.ChannelGreetMessageText.Replace("%user%", user.Mention).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                                if (!string.IsNullOrWhiteSpace(msg))
                                {
                                    try
                                    {
                                        var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
                                        if (conf.AutoDeleteGreetMessagesTimer > 0)
                                        {
                                            var t = Task.Run(async() =>
                                            {
                                                await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
                                                try { await toDelete.DeleteAsync().ConfigureAwait(false); } catch { }
                                            });
                                        }
                                    }
                                    catch (Exception ex) { _log.Warn(ex); }
                                }
                            }
                        }

                        if (conf.SendDmGreetMessage)
                        {
                            var channel = await user.CreateDMChannelAsync();

                            if (channel != null)
                            {
                                var msg = conf.DmGreetMessageText.Replace("%user%", user.Username).Replace("%server%", user.Guild.Name);
                                if (!string.IsNullOrWhiteSpace(msg))
                                {
                                    await channel.SendConfirmAsync(msg).ConfigureAwait(false);
                                }
                            }
                        }
                    }
                    catch { }
                });

                return(Task.CompletedTask);
            }
Ejemplo n.º 6
0
        public async Task warn(IGuildUser user, [Remainder] string reason = "")
        {
            var actionBy = Context.User;
            var DM       = await user.CreateDMChannelAsync();

            await ReplyAsync($"<:fireemblem:301087475508707328> {user.Username} has been **warned** by {actionBy.Username}. Reason: {reason}");

            await DM.SendMessageAsync($"You have been warned in {Context.Guild.Name}\nReason: {reason}");

            FS(user.Username, actionBy.Username, reason);
        }
Ejemplo n.º 7
0
        public async Task Ban(IUserMessage umsg, IGuildUser user, [Remainder] string msg = null)
        {
            var channel = (ITextChannel)umsg.Channel;

            if (string.IsNullOrWhiteSpace(msg))
            {
                msg = "See #rules";
            }
            if (msg.ToString().ToLower() == "bot")
            {
                msg = "See #rules, bot discussion is prohibited.";
            }
            if (umsg.Author.Id != user.Guild.OwnerId && user.Roles.Select(r => r.Position).Max() >= ((IGuildUser)umsg.Author).Roles.Select(r => r.Position).Max())
            {
                await channel.SendMessageAsync("You can't use this command on users with a role higher or equal to yours in the role hierarchy.");

                return;
            }
            if (umsg.Author.Id != user.Guild.OwnerId && user.Roles.Select(r => r.Position).Max() >= ((IGuildUser)umsg.Author).Roles.Select(r => r.Position).Max())
            {
                await channel.SendMessageAsync("You can't use this command on users with a role higher or equal to yours in the role hierarchy.");

                return;
            }
            try
            {
                var pogo = channel.Guild.GetTextChannel(211351526466125824);
                await pogo.SendMessageAsync("`" + umsg.Author.Username + "` **BANNED USER** " + $"`{user.Username}`:\n```ruby\n" + $"ID: {user.Id}\n" + $"Reason: {msg}\n" + "Timestamp: " + prettyCurrentTime + "```").ConfigureAwait(false);

                await(await user.CreateDMChannelAsync()).SendMessageAsync($"**You have been BANNED from `{channel.Guild.Name}` server.**\n" +
                                                                          $"Reason: {msg}").ConfigureAwait(false);
                await Task.Delay(2000).ConfigureAwait(false);
            }
            catch { }
            try
            {
                await channel.Guild.AddBanAsync(user, 7).ConfigureAwait(false);

                string[] kicks = new string[] { "/root/kick.gif", "/root/kick1.gif", "/root/kick2.gif", "/root/kick3.gif", "/root/kick4.gif", "/root/kick5.gif", "/root/kick6.gif" };
                Random   rnd   = new Random();
                await channel.SendFileAsync(kicks[rnd.Next(kicks.Length)]).ConfigureAwait(false);

                await channel.SendMessageAsync("Banned user " + user.Username + " Id: " + user.Id).ConfigureAwait(false);
            }
            catch
            {
                await channel.SendMessageAsync("Error. Most likely I don't have sufficient permissions.").ConfigureAwait(false);
            }
        }
Ejemplo n.º 8
0
        public async Task KickFromGang([Remainder] IGuildUser user)
        {
            if (!GangRepository.IsMemberOf(Context.User.Id, Context.Guild.Id, user.Id))
            {
                throw new Exception("This user is not a member of your gang!");
            }
            var gang = GangRepository.FetchGang(Context);

            GangRepository.RemoveMember(user.Id, Context.Guild.Id);
            await ReplyAsync($"{Context.User.Mention}, You have successfully kicked {user} from {gang.Name}");

            var channel = await user.CreateDMChannelAsync();

            await channel.SendMessageAsync($"You have been kicked from {gang.Name}.");
        }
Ejemplo n.º 9
0
        public async Task TimeinAsync([Summary("The user to timein")] IGuildUser target)
        {
            IRole      timedOutRole = Context.Guild.GetRole(248074293211037696);                                                                //  Stores the timed out role
            IRole      welcomeRole  = Context.Guild.GetRole(248434734240104459);                                                                //  Stores the welcome role
            IDMChannel dmchannel    = await target.CreateDMChannelAsync();                                                                      //  Creates a dmchannel with the target and stores it

            ITextChannel logchannel = await Context.Guild.GetTextChannelAsync(246572485292720139) as ITextChannel;                              //  Gets the logchannel and stores it

            await target.RemoveRolesAsync(timedOutRole);                                                                                        //  Removes the timed out role from the target

            await target.AddRolesAsync(welcomeRole);                                                                                            //  Assigns the welcome role to the target

            await dmchannel.SendMessageAsync($"You are no longer timed out from {target.Guild.ToString()}.");                                   //  Sends a message to the dmchannel

            await logchannel.SendMessageAsync($"USER: {target} ID: {target.Id} is no longer timed out.");                                       //  Sends a message to the logchannel
        }
Ejemplo n.º 10
0
        public async Task AddToGang(IGuildUser user)
        {
            if (GangRepository.InGang(user.Id, Context.Guild.Id))
            {
                throw new Exception("This user is already in a gang.");
            }
            if (GangRepository.IsFull(Context.User.Id, Context.Guild.Id))
            {
                throw new Exception("Your gang is already full!");
            }
            GangRepository.AddMember(Context.User.Id, Context.Guild.Id, user.Id);
            await ReplyAsync($"{user} is now a new member of your gang!");

            var channel = await user.CreateDMChannelAsync();

            await channel.SendMessageAsync($"Congrats! You are now a member of {GangRepository.FetchGang(Context).Name}!");
        }
Ejemplo n.º 11
0
            private static async Task UserJoined(IGuildUser user)
            {
                try
                {
                    var conf = GetOrAddSettingsForGuild(user.GuildId);

                    if (conf.SendChannelGreetMessage)
                    {
                        var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.GreetMessageChannelId);
                        if (channel != null) //maybe warn the server owner that the channel is missing
                        {
                            var msg = conf.ChannelGreetMessageText.Replace("%user%", user.Mention).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                            if (!string.IsNullOrWhiteSpace(msg))
                            {
                                try
                                {
                                    var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);

                                    if (conf.AutoDeleteGreetMessagesTimer > 0)
                                    {
                                        toDelete.DeleteAfter(conf.AutoDeleteGreetMessagesTimer);
                                    }
                                }
                                catch (Exception ex) { _log.Warn(ex); }
                            }
                        }
                    }

                    if (conf.SendDmGreetMessage)
                    {
                        var channel = await user.CreateDMChannelAsync();

                        if (channel != null)
                        {
                            var msg = conf.DmGreetMessageText.Replace("%user%", user.Username).Replace("%server%", user.Guild.Name);
                            if (!string.IsNullOrWhiteSpace(msg))
                            {
                                await channel.SendConfirmAsync(msg).ConfigureAwait(false);
                            }
                        }
                    }
                }
                catch { }
            }
Ejemplo n.º 12
0
        public async Task KickFromGang(IGuildUser user)
        {
            using (var db = new SQLite.Models.DbContext())
            {
                var gangRepo  = new GangRepository(db);
                var guildRepo = new GuildRepository(db);
                if (!(await gangRepo.IsMemberOf(Context.User.Id, Context.Guild.Id, user.Id)))
                {
                    throw new Exception("This user is not a member of your gang!");
                }
                var gang = await gangRepo.FetchGangAsync(Context.User.Id, Context.Guild.Id);

                await gangRepo.RemoveMemberAsync(user.Id, Context.Guild.Id);
                await ReplyAsync($"{Context.User.Mention}, You have successfully kicked {user} from {gang.Name}");

                var channel = await user.CreateDMChannelAsync();

                await channel.SendMessageAsync($"You have been kicked from {gang.Name}.");
            }
        }
Ejemplo n.º 13
0
        public async Task AddToGang(IGuildUser user)
        {
            using (var db = new SQLite.Models.DbContext())
            {
                var gangRepo = new GangRepository(db);
                if (await gangRepo.InGangAsync(user.Id, Context.Guild.Id))
                {
                    throw new Exception("This user is already in a gang.");
                }
                if (await gangRepo.IsFull(Context.User.Id, Context.Guild.Id))
                {
                    throw new Exception("Your gang is already full!");
                }
                await gangRepo.AddMemberAsync(Context.User.Id, Context.Guild.Id, user.Id);
                await ReplyAsync($"{user} is now a new member of your gang!");

                var channel = await user.CreateDMChannelAsync();

                await channel.SendMessageAsync($"Congrats! You are now a member of {(await gangRepo.FetchGangAsync(user.Id, Context.Guild.Id)).Name}!");
            }
        }
        private Task UserJoined(IGuildUser guildUser)
        {
            var _ = Task.Run(async() => {
                try {
                    using var uow = _db.UnitOfWork;
                    var gc        = uow.GuildConfigs.For(guildUser.GuildId);

                    if (gc.SendChannelGreetMessage)
                    {
                        await SendGreetMessage(guildUser.Guild, guildUser, await guildUser.Guild.GetTextChannelAsync(gc.GreetMessageChannelId).ConfigureAwait(false), gc.ChannelGreetMessageText, gc.AutoDeleteGreetMessagesTimer).ConfigureAwait(false);
                    }

                    if (gc.SendDmGreetMessage)
                    {
                        await SendGreetMessage(guildUser.Guild, guildUser, await guildUser.CreateDMChannelAsync().ConfigureAwait(false), gc.DmGreetMessageText, 0).ConfigureAwait(false);
                    }
                } catch { }
            });

            return(Task.CompletedTask);
        }
Ejemplo n.º 15
0
            public async Task Warn(IGuildUser user, [Remainder] string reason = null)
            {
                try
                {
                    await(await user.CreateDMChannelAsync()).EmbedAsync(new EmbedBuilder().WithErrorColor()
                                                                        .WithDescription(GetText("warned_on", Context.Guild.ToString()))
                                                                        .AddField(efb => efb.WithName(GetText("moderator")).WithValue(Context.User.ToString()))
                                                                        .AddField(efb => efb.WithName(GetText("reason")).WithValue(reason ?? "-")))
                    .ConfigureAwait(false);
                }
                catch { }
                var punishment = await InternalWarn(Context.Guild, user.Id, Context.User.ToString(), reason).ConfigureAwait(false);

                if (punishment == null)
                {
                    await ReplyConfirmLocalized("user_warned", Format.Bold(user.ToString())).ConfigureAwait(false);
                }
                else
                {
                    await ReplyConfirmLocalized("user_warned_and_punished", Format.Bold(user.ToString()), Format.Bold(punishment.ToString())).ConfigureAwait(false);
                }
            }
Ejemplo n.º 16
0
        public async Task TimeoutAsync([Summary("The user to timeout")] IGuildUser target, [Summary("Amount of seconds to timeout"), Optional] int seconds)
        {
            IRole      timedOutRole = Context.Guild.GetRole(248074293211037696);                                                                //  Stores a role, that serves as the timed out role
            IRole      welcomeRole  = Context.Guild.GetRole(248434734240104459);                                                                //  Stores a different role that is assigned to every newcomer in the server to get around discord's @everyone role
            IDMChannel dmchannel    = await target.CreateDMChannelAsync();                                                                      //  Stores a dmchannel with the target

            ITextChannel logchannel = await Context.Guild.GetTextChannelAsync(246572485292720139) as ITextChannel;                              //  Gets the logchannel and stores it

            seconds *= 1000;                                                                                                                    //  Takes the seconds parameter and converts it to miliseconds

            await target.AddRolesAsync(timedOutRole);                                                                                           //  Assigns the timed out role to the target

            await target.RemoveRolesAsync(welcomeRole);                                                                                         //  Removes the welcome role from the target

            if (seconds != 0)                                                                                                                   //  Checks to see if our seconds parameter isn't 0
            {
                await dmchannel.SendMessageAsync($"You have been timed out from {target.Guild.ToString()} for {seconds / 1000} seconds.");      //  Sends a message to the dmchannel

                await logchannel.SendMessageAsync($"USER: {target} ID: {target.Id} has been timed out for {seconds/1000} seconds.");            //  Sends a message to the logchannel

                await Task.Delay(seconds).ConfigureAwait(true);                                                                                 //  Stops the task for as many miliseconds as the seconds paramater is equal to. This doesn't work because it makes me unable to call any other functions

                await target.AddRolesAsync(welcomeRole);                                                                                        //  Assigns the welcome role to the target

                await target.RemoveRolesAsync(timedOutRole);                                                                                    //  Removes the timed out role from the target

                await dmchannel.SendMessageAsync($"You are no longer timed out from {target.Guild.ToString()}.");                               //  Sends text to the dmchannel

                await logchannel.SendMessageAsync($"USER: {target} ID: {target.Id} is no longer timed out.");                                   //  Sends text to the l
            }
            else                                                                                                                                //  Else
            {
                await dmchannel.SendMessageAsync($"You have been timed out from {target.Guild.ToString()} for an unspecified amount of time."); //  Sends a message to the dmchannel

                await logchannel.SendMessageAsync($"USER: {target} ID: {target.Id} has been timed out for an unspecified amount of time.");     //  Sends a message to the logchannel
            }
        }
            public async Task Warn(IGuildUser user, ModerationPoints points, [Remainder] string reason = null)
            {
                if (Context.User.Id == user.Guild.OwnerId || user.GetRoles().Where(r => r.IsHoisted).Select(r => r.Position).FallbackIfEmpty(int.MinValue).Max() < ((IGuildUser)Context.User).GetRoles().Where(r => r.IsHoisted).Select(r => r.Position).FallbackIfEmpty(int.MinValue).Max())
                {
                    try {
                        await(await user.CreateDMChannelAsync()).EmbedAsync(new EmbedBuilder().WithErrorColor().WithDescription(GetText("userpunish_warn_warned_on_server", Context.Guild.ToString())).AddField(efb => efb.WithName(GetText("userpunish_warn_reason")).WithValue(reason ?? "-"))).ConfigureAwait(false);
                    } catch { }

                    var punishment = await Service.Warn(Context.Guild, user.Id, Context.User.ToString(), reason, points).ConfigureAwait(false);

                    if (punishment == null)
                    {
                        await ConfirmLocalized("userpunish_warn_user_warned", Format.Bold(user.ToString())).ConfigureAwait(false);
                    }
                    else
                    {
                        await ConfirmLocalized("userpunish_warn_user_warned_and_punished", Format.Bold(user.ToString()), Format.Bold(punishment.ToString())).ConfigureAwait(false);
                    }
                }
                else
                {
                    await ErrorLocalized("userpunish_warn_hierarchy").ConfigureAwait(false);
                }
            }
Ejemplo n.º 18
0
            private Task UserJoined(IGuildUser user)
            {
                var joinedTask = Task.Run(async () =>
                {
                    try
                    {
                        GuildConfig conf;
                        using (var uow = DbHandler.UnitOfWork())
                        {
                            conf = uow.GuildConfigs.For(user.Guild.Id);
                        }

                        if (conf.SendChannelGreetMessage)
                        {
                            var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.GreetMessageChannelId);
                            if (channel != null) //maybe warn the server owner that the channel is missing
                            {
                                var msg = conf.ChannelGreetMessageText.Replace("%user%", user.Mention).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                                if (!string.IsNullOrWhiteSpace(msg))
                                {
                                    try
                                    {
                                        var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
                                        if (conf.AutoDeleteGreetMessagesTimer > 0)
                                        {
                                            var t = Task.Run(async () =>
                                            {
                                                await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
                                                try { await toDelete.DeleteAsync().ConfigureAwait(false); } catch { }
                                            });
                                        }
                                    }
                                    catch (Exception ex) { _log.Warn(ex); }
                                }
                            }
                        }

                        if (conf.SendDmGreetMessage)
                        {
                            var channel = await user.CreateDMChannelAsync();

                            if (channel != null)
                            {
                                var msg = conf.DmGreetMessageText.Replace("%user%", user.Username).Replace("%server%", user.Guild.Name);
                                if (!string.IsNullOrWhiteSpace(msg))
                                {
                                    await channel.SendMessageAsync(msg).ConfigureAwait(false);
                                }
                            }
                        }
                    }
                    catch { }
                });
                return Task.CompletedTask;
            }
Ejemplo n.º 19
0
            private static Task UserJoined(IGuildUser user)
            {
                var _ = Task.Run(async() =>
                {
                    try
                    {
                        var conf = GetOrAddSettingsForGuild(user.GuildId);

                        if (conf.SendChannelGreetMessage)
                        {
                            var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.GreetMessageChannelId);
                            if (channel != null) //maybe warn the server owner that the channel is missing
                            {
                                CREmbed embedData;
                                if (CREmbed.TryParse(conf.ChannelGreetMessageText, out embedData))
                                {
                                    embedData.PlainText   = embedData.PlainText?.Replace("%user%", user.Mention).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                                    embedData.Description = embedData.Description?.Replace("%user%", user.Mention).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                                    embedData.Title       = embedData.Title?.Replace("%user%", user.ToString()).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                                    try
                                    {
                                        var toDelete = await channel.EmbedAsync(embedData.ToEmbed(), embedData.PlainText ?? "").ConfigureAwait(false);
                                        if (conf.AutoDeleteGreetMessagesTimer > 0)
                                        {
                                            toDelete.DeleteAfter(conf.AutoDeleteGreetMessagesTimer);
                                        }
                                    }
                                    catch (Exception ex) { _log.Warn(ex); }
                                }
                                else
                                {
                                    var msg = conf.ChannelGreetMessageText.Replace("%user%", user.Mention).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                                    if (!string.IsNullOrWhiteSpace(msg))
                                    {
                                        try
                                        {
                                            var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
                                            if (conf.AutoDeleteGreetMessagesTimer > 0)
                                            {
                                                toDelete.DeleteAfter(conf.AutoDeleteGreetMessagesTimer);
                                            }
                                        }
                                        catch (Exception ex) { _log.Warn(ex); }
                                    }
                                }
                            }
                        }

                        if (conf.SendDmGreetMessage)
                        {
                            var channel = await user.CreateDMChannelAsync();

                            if (channel != null)
                            {
                                CREmbed embedData;
                                if (CREmbed.TryParse(conf.ChannelGreetMessageText, out embedData))
                                {
                                    embedData.PlainText   = embedData.PlainText?.Replace("%user%", user.ToString()).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                                    embedData.Description = embedData.Description?.Replace("%user%", user.ToString()).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                                    embedData.Title       = embedData.Title?.Replace("%user%", user.ToString()).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                                    try
                                    {
                                        await channel.EmbedAsync(embedData.ToEmbed(), embedData.PlainText ?? "").ConfigureAwait(false);
                                    }
                                    catch (Exception ex) { _log.Warn(ex); }
                                }
                                else
                                {
                                    var msg = conf.DmGreetMessageText.Replace("%user%", user.ToString()).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
                                    if (!string.IsNullOrWhiteSpace(msg))
                                    {
                                        await channel.SendConfirmAsync(msg).ConfigureAwait(false);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                });

                return(Task.CompletedTask);
            }
Ejemplo n.º 20
0
        public async Task Trade(IGuildUser userToTrade, int exchangeItemQuantity, [Own] Item itemInExchange, int requestedItemQuantity, Item requestedItem)
        {
            if (userToTrade.Id == Context.User.Id)
            {
                ReplyError("It takes great skill and concetration to actually reach full retard by trading with yourself. You are not quite there.");
            }
            else if (exchangeItemQuantity < 0 || requestedItemQuantity < 0)
            {
                ReplyError("You may not trade negative items.");
            }

            var userDM = await userToTrade.CreateDMChannelAsync();

            var key     = CryptoRandom.Next();
            var firstS  = exchangeItemQuantity == 1 ? string.Empty : "s";
            var secondS = requestedItemQuantity == 1 ? string.Empty : "s";

            await userDM.SendAsync($"**Offer:** {exchangeItemQuantity} {itemInExchange.Name}{firstS}\n" +
                                   $"**Request:** {requestedItemQuantity} {requestedItem.Name}{secondS}\n\n" +
                                   $"Please respond with \"{key}\" within 5 minutes to accept this trade.",
                                   $"Trade Request from {Context.User}");

            await ReplyAsync($"You have successfully informed {userToTrade.Boldify()} of your trade request.");

            var answer = await _interactiveService.WaitForMessage(userDM, x => x.Content == key.ToString(), TimeSpan.FromMinutes(5));

            if (answer != null)
            {
                var newOffererDbuser = await _userRepo.GetUserAsync(Context.GUser);

                var newRequesterDbuser = await _userRepo.GetUserAsync(userToTrade);

                if (!newOffererDbuser.Inventory.Contains(itemInExchange.Name))
                {
                    await userDM.SendErrorAsync($"{Context.User.Boldify()} does not own the following item: {itemInExchange.Name}.");
                }
                else if (!newRequesterDbuser.Inventory.Contains(requestedItem.Name))
                {
                    await userDM.SendErrorAsync($"You do not own the following item: {requestedItem.Name}.");
                }
                else if (!(newOffererDbuser.Inventory[itemInExchange.Name].AsInt32 >= exchangeItemQuantity))
                {
                    await userDM.SendErrorAsync($"{Context.User.Boldify()} does not own {exchangeItemQuantity} {itemInExchange.Name}{firstS}.");
                }
                else if (!(newRequesterDbuser.Inventory[requestedItem.Name].AsInt32 >= requestedItemQuantity))
                {
                    await userDM.SendErrorAsync($"You do not own {requestedItemQuantity} {requestedItem.Name}{secondS}.");
                }
                else
                {
                    await _gameService.ModifyInventoryAsync(newOffererDbuser, itemInExchange.Name, -exchangeItemQuantity);

                    await _gameService.ModifyInventoryAsync(newOffererDbuser, requestedItem.Name, requestedItemQuantity);

                    await _gameService.ModifyInventoryAsync(newRequesterDbuser, itemInExchange.Name, exchangeItemQuantity);

                    await _gameService.ModifyInventoryAsync(newRequesterDbuser, requestedItem.Name, -requestedItemQuantity);

                    var message = $"**Offer:** {exchangeItemQuantity} {itemInExchange.Name}{firstS}\n" +
                                  $"**Request:** {requestedItemQuantity} {requestedItem.Name}{secondS}\n\n";

                    await userDM.SendAsync(message, $"Completed Trade with {Context.User}");

                    await Context.GUser.TryDMAsync(message, $"Completed Trade with {userToTrade}");
                }
            }
        }
Ejemplo n.º 21
0
        public async Task AcceptOrder(int id)
        {
            if (id > 0)
            {
                Chef c = SS.chefList.FirstOrDefault(a => a.Value.ChefId == Context.User.Id).Value;
                if (SS.activeOrders.FirstOrDefault(s => s.Value.Id == id).Value != null)
                {
                    Sandwich order = SS.activeOrders.FirstOrDefault(a => a.Value.Id == id).Value;
                    if (SS.toBeDelivered.Contains(order.Id))
                    {
                        await ReplyAsync("This order is already ready to be delivered! :angry: "); return;
                    }
                    try //TODO: FIX 403 ERROR
                    {
                        await ReplyAsync($"{Context.User.Mention} Sandwich order is now ready for delivery! Please assemble the sandwich, once you are complete. `;deliver {id}` to continue! Type `;orderinfo {id}`(short: `;oi {id}`) if you need more info. :wave: ");

                        IGuild s = await Context.Client.GetGuildAsync(order.GuildId);

                        ITextChannel ch = await s.GetTextChannelAsync(order.ChannelId);

                        IGuildUser u = await s.GetUserAsync(order.UserId);

                        try
                        {
                            IDMChannel dm = await u.CreateDMChannelAsync();

                            var builder = new EmbedBuilder();

                            builder.ThumbnailUrl = Context.User.GetAvatarUrl();
                            builder.Title        = $"Your order has been accepted by {Context.User.Username}#{Context.User.Discriminator}!";
                            var desc = $"```{order.Desc}```\n" +
                                       $"Id: `{order.Id}`\n" +
                                       $"**Watch this chat for an updates on when it is on it's way! It is ready for delivery!";
                            builder.Description = desc;
                            builder.Color       = new Color(36, 78, 145);
                            builder.Url         = "https://discord.gg/XgeZfE2";
                            builder.WithFooter(x =>
                            {
                                x.IconUrl = u.GetAvatarUrl();
                                x.Text    = $"Ordered at: {order.date}.";
                            });
                            builder.Timestamp = DateTime.UtcNow;
                            order.Status      = OrderStatus.ReadyToDeliver; //like a dirty jew
                            SS.toBeDelivered.Add(order.Id);
                            c.ordersAccepted += 1;
                            await dm.SendMessageAsync("", embed : builder);

                            SS.Save();
                        }
                        catch (NullReferenceException)
                        {
                            await ReplyAsync("Null ref. Did they kick our bot or delete the channel? Try to add the user and ask.");

                            //delete it too???
                        }
                        catch (Exception e)
                        {
                            await ReplyAsync("Error :ghost:");
                            await ReplyAsync($"```{e}```");

                            await ch.SendMessageAsync(u.Mention + " I cannot send dms to you! Please give me the ability to by going to the servers settings in the top left > privacy settings and enabled direct messages from server users. Thank you. If you believe this error was a mistake, please join our server using `;server` and contact Fires#1043.");

                            return;
                        }
                    }
                    catch (Exception d)
                    {
                        await ReplyAsync("SEND ERROR TO Fires#4553 IMMEDIATELY");
                        await ReplyAsync($"```{d}```");
                    }
                    SS.Save(); return;
                }
                else
                {
                    await ReplyAsync("Sorry bud this order doesn't exist!"); return;
                }
            }
        }
Ejemplo n.º 22
0
 public static async Task <IUserMessage> SendFileAsync(this IGuildUser user, Stream fileStream, string fileName, string caption = null, bool isTTS = false) =>
 await(await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(fileStream, fileName, caption, isTTS).ConfigureAwait(false);
Ejemplo n.º 23
0
 public static async Task <IUserMessage> SendMessageAsync(this IGuildUser user, string message, bool isTTS = false) =>
 await(await user.CreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(message, isTTS).ConfigureAwait(false);
Ejemplo n.º 24
0
        public async Task Deliver(int id)
        {
            if (id > 0)
            {
                if (SS.toBeDelivered.Contains(id))
                {
                    if (SS.activeOrders.FirstOrDefault(s => s.Value.Id == id).Value != null)
                    {
                        Chef     c     = SS.chefList.FirstOrDefault(a => a.Value.ChefId == Context.User.Id).Value;
                        Sandwich order = SS.activeOrders.FirstOrDefault(s => s.Value.Id == id).Value;
                        if (order.Status == OrderStatus.ReadyToDeliver)
                        {
                            try
                            {
                                Console.WriteLine("passed finish");
                                await ReplyAsync("DMing you an invite! Go deliver it! Remember to be nice and ask for `;feedback`");

                                IGuild s = await Context.Client.GetGuildAsync(order.GuildId);

                                ITextChannel ch = await s.GetTextChannelAsync(order.ChannelId);

                                IGuildUser u = await s.GetUserAsync(order.UserId);

                                IDMChannel dm = await u.CreateDMChannelAsync();

                                await dm.SendMessageAsync($"Your sandwich is being delivered soon! Watch out!");

                                IInvite inv = await ch.CreateInviteAsync(0, 1, false, true);

                                IDMChannel artistdm = await Context.User.CreateDMChannelAsync();

                                var builder = new EmbedBuilder();
                                builder.ThumbnailUrl = order.AvatarUrl;
                                builder.Title        = $"Your order is being delivered by {Context.User.Username}#{Context.User.Discriminator}!";
                                var desc = $"```{order.Desc}```\n" +
                                           $"**Incoming sandwich! Watch {order.GuildName}!**";
                                builder.Description = desc;
                                builder.Color       = new Color(163, 198, 255);
                                builder.WithFooter(x =>
                                {
                                    x.IconUrl = u.GetAvatarUrl();
                                    x.Text    = $"Ordered at: {order.date}.";
                                });
                                builder.Timestamp = DateTime.UtcNow;
                                await artistdm.SendMessageAsync(inv.ToString());

                                SS.cache.Add(order);
                                order.Status = OrderStatus.Delivered;
                                SS.toBeDelivered.Remove(order.Id);
                                SS.activeOrders.Remove(order.Id);
                                SS.hasAnOrder.Remove(order.UserId);
                                c.ordersDelivered += 1;
                                //await e.Channel.SendMessage("The Order has been completed and removed from the system. You cannot go back now!");
                                SS.Save();
                            }
                            catch (Exception ex)
                            {
                                await ReplyAsync(":ghost:");
                                await ReplyAsync($"```{ex}```"); return;
                            }
                        }
                        else
                        {
                            await ReplyAsync($"This order is not ready to be delivered just yet! It is currently Order Status {order.Status}"); return;
                        }
                    }
                    else
                    {
                        await ReplyAsync("Invalid order probably (tell Fires its a problem with the checky thingy, the thing thing)"); return;
                    }
                }
                else
                {
                    await ReplyAsync("You are not high enough rank to deliver orders!"); return;
                }
            }
            else
            {
                await ReplyAsync("This order is not ready to be delivered yet! (this error can also occur if you are not using the right id)"); return;
            }
        }
Ejemplo n.º 25
0
        public async Task DenyOrder(int id, [Remainder] string reason)
        {
            if (SS.activeOrders.FirstOrDefault(s => s.Value.Id == id).Value != null)
            {
                Sandwich order = SS.activeOrders.FirstOrDefault(a => a.Value.Id == id).Value;
                order.Status = OrderStatus.Delivered;
                SS.activeOrders.Remove(id);
                await ReplyAsync($"Deleted order {order.Id}!");

                IGuild s = await Context.Client.GetGuildAsync(order.GuildId);

                ITextChannel ch = await s.GetTextChannelAsync(order.ChannelId);

                IGuildUser u = await s.GetUserAsync(order.UserId);

                IDMChannel dm = await u.CreateDMChannelAsync();

                SS.hasAnOrder.Remove(order.UserId);
                SS.totalOrders -= 1;
                await dm.SendMessageAsync($"Your sandwich order has been denied! ", embed : new EmbedBuilder()
                                          .WithThumbnailUrl(Context.User.GetAvatarUrl())
                                          .WithUrl("https://discord.gg/XgeZfE2")
                                          .AddField(builder =>
                {
                    builder.Name = "Order:";
                    builder.Value = order.Desc;
                    builder.IsInline = true;
                })
                                          .AddField(builder =>
                {
                    builder.Name = "Denied By:";
                    builder.Value = string.Join("#", Context.User.Username, Context.User.Discriminator);
                    builder.IsInline = true;
                })
                                          .AddField(builder =>
                {
                    builder.Name = "Denied because:";
                    builder.Value = reason;
                    builder.IsInline = true;
                })
                                          .AddField(builder =>
                {
                    builder.Name = "Ordered at:";
                    builder.Value = order.date;
                    builder.IsInline = true;
                })
                                          .AddField(builder =>
                {
                    builder.Name = "Server:";
                    builder.Value = order.GuildName;
                    builder.IsInline = true;
                })
                                          .AddField(builder =>
                {
                    builder.Name = "Order Status:";
                    builder.Value = order.Status;
                    builder.IsInline = true;
                })
                                          .AddField(builder =>
                {
                    builder.Name = "Order Id:";
                    builder.Value = order.Id;
                    builder.IsInline = true;
                })
                                          .WithCurrentTimestamp()
                                          .WithTitle("Denied order:"));
            }
            else
            {
                await ReplyAsync("This order does not exist!"); return;
            }
        }
Ejemplo n.º 26
0
        public async Task Ban(IUserMessage umsg, IGuildUser user, [Remainder] string msg = null)
        {
            var channel = (ITextChannel)umsg.Channel;
            if (string.IsNullOrWhiteSpace(msg))
            {
                msg = "❗️No reason provided.";
            }
            if (umsg.Author.Id != user.Guild.OwnerId && user.Roles.Select(r=>r.Position).Max() >= ((IGuildUser)umsg.Author).Roles.Select(r => r.Position).Max())
            {
                await channel.SendMessageAsync("⚠️ You can't use this command on users with a role higher or equal to yours in the role hierarchy.");
                return;
            }
            try
            {
                await (await user.CreateDMChannelAsync()).SendMessageAsync($"⛔️ **You have been BANNED from `{channel.Guild.Name}` server.**\n" +
                                        $"⚖ *Reason:* {msg}").ConfigureAwait(false);
                await Task.Delay(2000).ConfigureAwait(false);
            }
            catch { }
            try
            {
                await channel.Guild.AddBanAsync(user, 7).ConfigureAwait(false);

                await channel.SendMessageAsync("⛔️ **Banned** user **" + user.Username + "** ID: `" + user.Id + "`").ConfigureAwait(false);
            }
            catch
            {
                await channel.SendMessageAsync("⚠️ **Error.** Most likely I don't have sufficient permissions.").ConfigureAwait(false);
            }
        }
Ejemplo n.º 27
0
        private async void Kick(IGuildUser user, IUserMessage message, IGuild guild)
        {
            try {
                if (await guild.GetUserAsync(user.Id) == null)
                {
                    //already kicked by ReactionAdded event or server left
                    return;
                }

                List <IUser> yesUser = new List <IUser>(await message.GetReactionUsersAsync(Information.VotekickYes));
                List <IUser> noUser  = new List <IUser>(await message.GetReactionUsersAsync(Information.VotekickNo));

                string nl = Environment.NewLine;

                // -1 for own reaction
                int yes = yesUser.Count - 1;
                int no  = noUser.Count - 1;
                //only users in a voice channel can votekick
                int online = new List <IGuildUser>(((await guild.GetUsersAsync()).Where(u => (u.Status == UserStatus.Online && u.VoiceChannel != null)))).Count;

                //more than half of server users voted yes
                if (yes > online / 2 && no < yes)
                {
                    //check if admin voted no -> dismiss vote
                    foreach (IUser iuser in noUser)
                    {
                        if (CheckIfAdmin(iuser as IGuildUser))
                        {
                            await message.Channel.SendMessageAsync($"An admin voted _no_, _{Helper.GetName(user)}_ cannot be kicked!");

                            return;
                        }
                    }

                    IInviteMetadata invite = await((IGuildChannel)message.Channel).CreateInviteAsync(maxUses: 1);
                    try {
                        IDMChannel dm = await user.CreateDMChannelAsync();

                        await dm.SendMessageAsync($"You've been kicked from the _{guild.Name}_ guild by votekick!" + nl +
                                                  $"As I'm very generous today, here's an invite link to the _{guild.Name}_ guild:" + nl + invite.Url);
                    } catch {
                        //user is not allowing DMs?
                        await message.Channel.SendMessageAsync($"{Helper.GetName(user)} is not allowing private messages, " +
                                                               "someone gotta send him an invite link again.." + nl + invite.Url);
                    }
                    await user.KickAsync();

                    await message.Channel.SendMessageAsync($"You bullies kicked the poor {Helper.GetName(user)}..");

                    try {
                        Cirilla.Client.ReactionAdded -= ReactionAdded;
                    } catch {
                        //event removed
                    }
                }
                else
                {
                    await message.Channel.SendMessageAsync($"Time's up. Less than half of the online users ({yes}) " +
                                                           $"voted to kick {Helper.GetName(user)}. Votekick dismissed.");
                }
            } catch {
                await message.Channel.SendMessageAsync($"Could not kick {Helper.GetName(user)}.. :confused:");
            }
        }
Ejemplo n.º 28
0
 public static async Task <IUserMessage> SendErrorAsync(this IGuildUser user, string error)
 => await(await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new Embed()
 {
     Description = error, Color = NadekoBot.ErrorColor
 });
Ejemplo n.º 29
0
 public static async Task <IUserMessage> SendConfirmAsync(this IGuildUser user, string title, string text, string url = null)
 => await(await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new Embed()
 {
     Description = text, Title = title, Url = url, Color = NadekoBot.OkColor
 });