Ejemplo n.º 1
0
        private async Task ExecuteTempmuteCommand(CommandContext ctx,
                                                  DiscordMember member,
                                                  TimeSpan time,
                                                  String Reason,
                                                  Boolean Silent,
                                                  Boolean DmMember)
        {
            if (!ctx.Member.HasPermission("insanitybot.moderation.tempmute"))
            {
                await ctx.RespondAsync(InsanityBot.LanguageConfig["insanitybot.error.lacking_permission"]);

                return;
            }

            String MuteReason = Reason switch
            {
                "usedefault" => GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.no_reason_given"],
                                                   ctx, member),
                _ => GetFormattedString(Reason, ctx, member)
            };

            DiscordEmbedBuilder embedBuilder = null;

            DiscordEmbedBuilder moderationEmbedBuilder = new DiscordEmbedBuilder
            {
                Title  = "TEMPMUTE",
                Color  = DiscordColor.Red,
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text = "InsanityBot - ExaInsanity 2020-2021"
                }
            };

            moderationEmbedBuilder.AddField("Moderator", ctx.Member.Mention, true)
            .AddField("Member", member.Mention, true)
            .AddField("Duration", time.ToString(), true)
            .AddField("Reason", MuteReason, true);

            try
            {
                MuteStartingEvent();

                Timer callbackTimer = new Timer(DateTime.Now.Add(time), $"tempmute_{member.Id}");
                moderationEmbedBuilder.AddField("Timer GUID", callbackTimer.Guid.ToString(), true);
                TimeHandler.AddTimer(callbackTimer);

                member.AddModlogEntry(ModlogEntryType.mute, MuteReason);
                embedBuilder = new DiscordEmbedBuilder
                {
                    Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.mute.success"],
                                                     ctx, member),
                    Color  = DiscordColor.Red,
                    Footer = new DiscordEmbedBuilder.EmbedFooter
                    {
                        Text = "InsanityBot - ExaInsanity 2020-2021"
                    }
                };
                _ = member.GrantRoleAsync(InsanityBot.HomeGuild.GetRole(
                                              ToUInt64(InsanityBot.Config["insanitybot.identifiers.moderation.mute_role_id"])),
                                          MuteReason);
                _ = InsanityBot.HomeGuild.GetChannel(ToUInt64(InsanityBot.Config["insanitybot.identifiers.commands.modlog_channel_id"]))
                    .SendMessageAsync(embed: moderationEmbedBuilder.Build());
            }
            catch
            {
                embedBuilder = new DiscordEmbedBuilder
                {
                    Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.mute.failure"], ctx, member),
                    Color       = DiscordColor.Red,
                    Footer      = new DiscordEmbedBuilder.EmbedFooter
                    {
                        Text = "InsanityBot - ExaInsanity 2020-2021"
                    }
                };
            }
            finally
            {
                if (embedBuilder == null)
                {
                    InsanityBot.Client.Logger.LogError(new EventId(1131, "Tempmute"),
                                                       "Could not execute tempmute command, an unknown exception occured.");
                }
                else
                {
                    await ctx.RespondAsync(embed : embedBuilder.Build());
                }
            }
        }
Ejemplo n.º 2
0
        private async Task ExecuteKickCommand(CommandContext ctx,
                                              DiscordMember member,
                                              String Reason,
                                              Boolean Silent,
                                              Boolean DmMember,
                                              Boolean Invite)
        {
            if (!ctx.Member.HasPermission("insanitybot.moderation.kick"))
            {
                await ctx.RespondAsync(InsanityBot.LanguageConfig["insanitybot.error.lacking_permission"]);

                return;
            }

            //actually do something with the usedefault value
            String KickReason = Reason switch
            {
                "usedefault" => GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.no_reason_given"],
                                                   ctx, member),
                _ => GetFormattedString(Reason, ctx, member)
            };

            DiscordEmbedBuilder embedBuilder = null;

            DiscordEmbedBuilder moderationEmbedBuilder = new DiscordEmbedBuilder
            {
                Title  = "KICK",
                Color  = DiscordColor.Red,
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text = "InsanityBot - ExaInsanity 2020-2021"
                }
            };

            moderationEmbedBuilder.AddField("Moderator", ctx.Member.Mention, true)
            .AddField("Member", member.Mention, true)
            .AddField("Reason", KickReason, true);

            try
            {
                member.AddModlogEntry(ModlogEntryType.kick, KickReason);
                embedBuilder = new DiscordEmbedBuilder
                {
                    Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.kick.success"],
                                                     ctx, member),
                    Color  = DiscordColor.Red,
                    Footer = new DiscordEmbedBuilder.EmbedFooter
                    {
                        Text = "InsanityBot - ExaInsanity 2020-2021"
                    }
                };

                if (Invite || DmMember)
                {
                    var channel = await member.CreateDmChannelAsync();

                    if (DmMember)
                    {
                        await channel.SendMessageAsync(GetReason(GetFormattedString(
                                                                     InsanityBot.LanguageConfig["insanitybot.moderation.kick.reason"],
                                                                     ctx, member), KickReason));
                    }
                    if (Invite)
                    {
                        await channel.SendMessageAsync((await ctx.Channel.CreateInviteAsync()).ToString());
                    }
                }

                _ = member.RemoveAsync(KickReason);
                _ = InsanityBot.HomeGuild.GetChannel(ToUInt64(InsanityBot.Config["insanitybot.identifiers.commands.modlog_channel_id"]))
                    .SendMessageAsync(embed: moderationEmbedBuilder.Build());
            }
            catch (Exception e)
            {
                embedBuilder = new DiscordEmbedBuilder
                {
                    Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.kick.failure"],
                                                     ctx, member),
                    Color  = DiscordColor.Red,
                    Footer = new DiscordEmbedBuilder.EmbedFooter
                    {
                        Text = "InsanityBot - ExaInsanity 2020-2021"
                    }
                };
                InsanityBot.Client.Logger.LogError($"{e}: {e.Message}");
            }
            finally
            {
                if (!Silent)
                {
                    await ctx.RespondAsync(embed : embedBuilder.Build());
                }
            }
        }
    }
Ejemplo n.º 3
0
        private async Task ExecuteMuteCommand(CommandContext ctx,
                                              DiscordMember member,
                                              String Reason,
                                              Boolean Silent,
                                              Boolean DmMember)
        {
            if (!ctx.Member.HasPermission("insanitybot.moderation.mute"))
            {
                await ctx.RespondAsync(InsanityBot.LanguageConfig["insanitybot.error.lacking_permission"]);

                return;
            }

            //actually do something with the usedefault value
            String MuteReason = Reason switch
            {
                "usedefault" => GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.no_reason_given"],
                                                   ctx, member),
                _ => GetFormattedString(Reason, ctx, member)
            };

            DiscordEmbedBuilder embedBuilder = null;

            DiscordEmbedBuilder moderationEmbedBuilder = new DiscordEmbedBuilder
            {
                Title  = "MUTE",
                Color  = DiscordColor.Red,
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text = "InsanityBot - ExaInsanity 2020-2021"
                }
            };

            moderationEmbedBuilder.AddField("Moderator", ctx.Member.Mention, true)
            .AddField("Member", member.Mention, true)
            .AddField("Reason", MuteReason, true);

            try
            {
                member.AddModlogEntry(ModlogEntryType.mute, MuteReason);
                embedBuilder = new DiscordEmbedBuilder
                {
                    Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.mute.success"],
                                                     ctx, member),
                    Color  = DiscordColor.Red,
                    Footer = new DiscordEmbedBuilder.EmbedFooter
                    {
                        Text = "InsanityBot - ExaInsanity 2020-2021"
                    }
                };
                _ = member.GrantRoleAsync(InsanityBot.HomeGuild.GetRole(
                                              ToUInt64(InsanityBot.Config["insanitybot.identifiers.moderation.mute_role_id"])),
                                          MuteReason);
                _ = InsanityBot.HomeGuild.GetChannel(ToUInt64(InsanityBot.Config["insanitybot.identifiers.commands.modlog_channel_id"]))
                    .SendMessageAsync(embed: moderationEmbedBuilder.Build());
            }
            catch (Exception e)
            {
                embedBuilder = new DiscordEmbedBuilder
                {
                    Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.mute.failure"],
                                                     ctx, member),
                    Color  = DiscordColor.Red,
                    Footer = new DiscordEmbedBuilder.EmbedFooter
                    {
                        Text = "InsanityBot - ExaInsanity 2020-2021"
                    }
                };
                InsanityBot.Client.Logger.LogError($"{e}: {e.Message}");
            }
            finally
            {
                await ctx.RespondAsync(embed : embedBuilder.Build());
            }
        }
    }
Ejemplo n.º 4
0
        private async Task ExecuteWarn(CommandContext ctx,
                                       DiscordMember target,
                                       String reason,
                                       Boolean silent,
                                       Boolean dmMember)
        {
            if (!ctx.Member.HasPermission("insanitybot.moderation.warn"))
            {
                await ctx.RespondAsync(InsanityBot.LanguageConfig["insanitybot.error.lacking_permission"]);

                return;
            }

            //if silent - delete the warn command
            if (silent)
            {
                await ctx.Message.DeleteAsync();
            }

            //actually do something with the usedefault value
            String WarnReason = reason switch
            {
                "usedefault" => GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.no_reason_given"],
                                                   ctx, target),
                _ => GetFormattedString(reason, ctx, target)
            };

            DiscordEmbedBuilder embedBuilder = null;

            DiscordEmbedBuilder moderationEmbedBuilder = new DiscordEmbedBuilder
            {
                Title  = "Warn",
                Color  = DiscordColor.Yellow,
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text = "InsanityBot - ExaInsanity 2020-2021"
                }
            };

            moderationEmbedBuilder.AddField("Moderator", ctx.Member.Mention, true)
            .AddField("Member", target.Mention, true)
            .AddField("Reason", WarnReason, true);

            try
            {
                target.AddModlogEntry(ModlogEntryType.warn, WarnReason);
                embedBuilder = new DiscordEmbedBuilder
                {
                    Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.warn.success"],
                                                     ctx, target),
                    Color  = DiscordColor.Red,
                    Footer = new DiscordEmbedBuilder.EmbedFooter
                    {
                        Text = "InsanityBot - ExaInsanity 2020-2021"
                    }
                };
                _ = InsanityBot.HomeGuild.GetChannel(ToUInt64(InsanityBot.Config["insanitybot.identifiers.commands.modlog_channel_id"]))
                    .SendMessageAsync(embed: moderationEmbedBuilder.Build());
            }
            catch (Exception e)
            {
                embedBuilder = new DiscordEmbedBuilder
                {
                    Description = GetFormattedString(InsanityBot.LanguageConfig["insanitybot.moderation.warn.failure"],
                                                     ctx, target),
                    Color  = DiscordColor.Red,
                    Footer = new DiscordEmbedBuilder.EmbedFooter
                    {
                        Text = "InsanityBot - ExaInsanity 2020-2021"
                    }
                };
                InsanityBot.Client.Logger.LogError($"{e}: {e.Message}");
            }
            finally
            {
                if (!silent)
                {
                    await ctx.RespondAsync(embed : embedBuilder.Build());
                }
                if (dmMember)
                {
                    embedBuilder.Description = GetReason(InsanityBot.LanguageConfig["insanitybot.moderation.warn.reason"], WarnReason);
                    await(await target.CreateDmChannelAsync()).SendMessageAsync(embed: embedBuilder.Build());
                }
            }
        }
    }