Пример #1
0
    // Use this for initialization
    void Start()
    {
//        DMInvoker invoker=new DMInvoker();
//
//        invoker.AddCommand(new DMCommand1(new DMReceiver1()));
//
//	    invoker.ExecuteCmd();

        cmd = new DMCommand1(new DMReceiver1());

        cmd.Execute();
    }
Пример #2
0
 public void AddCommand(DMCommand cmd)
 {
     commands.Add(cmd);
 }
Пример #3
0
        public async Task Ban(CommandContext ctx, [HelpDescription("The person to ban")] DiscordUser target, [RemainingText] string reason = "Not given.")
        {
            var user = await ctx.Guild.GetMemberAsync(target.Id);

            var bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id);

            if (!CanExecuteCommand(out reason))
            {
                await DenyBanAsync(reason);

                return;
            }

            async Task DenyBanAsync(string reason)
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithAuthor(ctx.Member.DisplayName, "", ctx.Member.AvatarUrl)
                                       .WithColor(DiscordColor.Red).WithDescription(reason)
                                       .WithFooter("Silk", ctx.Client.CurrentUser.AvatarUrl)
                                       .WithTimestamp(DateTime.Now));
            }

            bool CanExecuteCommand(out string reason)
            {
                if (target == bot)
                {
                    reason = $"I can't ban myself!";
                    return(false);
                }
                if (!ctx.Member.HasPermission(Permissions.BanMembers))
                {
                    reason = $"You do not have permission to ban members!";
                    return(false);
                }
                if (user.IsAbove(bot))
                {
                    reason = $"{target.Mention} has a role {user.GetHighestRoleMention()} that is above mine, and I cannot ban them!";
                    return(false);
                }
                reason = null;
                return(true);
            }

            var userBannedEmbed = new DiscordEmbedBuilder(EmbedHelper.CreateEmbed(ctx, $"You've been banned from {ctx.Guild.Name}!", "")).AddField("Reason:", $"{(reason == "" ? "No reason provided." : reason)}");

            try
            {
                await DMCommand.DM(ctx, target, userBannedEmbed);
            }
            catch (Exception e) { ctx.Client.DebugLogger.LogMessage(LogLevel.Error, "Silk", e.Message, DateTime.Now, e); }



            await ctx.Guild.BanMemberAsync(user, 7, reason == ""? "No reason provided" : reason);

            await ctx.Channel.SendMessageAsync(embed : new DiscordEmbedBuilder()
                                               .WithAuthor(ctx.Member.DisplayName, "", ctx.Member.AvatarUrl)
                                               .WithColor(DiscordColor.SpringGreen)
                                               .WithDescription($":hammer: banned {target.Mention}!")
                                               .WithFooter("Silk", ctx.Client.CurrentUser.AvatarUrl)
                                               .WithTimestamp(DateTime.Now));
        }
Пример #4
0
        public async Task Ban(CommandContext ctx, [HelpDescription("The person to ban")] DiscordMember target, [RemainingText] string reason = "No reason given.")
        {
            if (!ServerConfigurationManager.LocalConfiguration.ContainsKey(ctx.Guild.Id))
            {
                await ServerConfigurationManager.Instance.GenerateConfigurationFromIdAsync(ctx.Guild.Id);
            }
            var user = await ctx.Guild.GetMemberAsync(target.Id);

            var bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id);

            if (!CanExecuteCommand(out var errorReason))
            {
                await DenyBanAsync(errorReason);

                return;
            }

            async Task DenyBanAsync(string errorReason)
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder().WithAuthorExtension(ctx.Member.DisplayName, ctx.Member.AvatarUrl)
                                       .WithColor(DiscordColor.Red).WithDescription(errorReason)
                                       .WithFooter("Silk", ctx.Client.CurrentUser.AvatarUrl)
                                       .WithTimestamp(DateTime.Now));
            }

            bool CanExecuteCommand(out string errorReason)
            {
                if (target == bot)
                {
                    errorReason = $"I can't ban myself!";
                    return(false);
                }
                if (!ctx.Member.HasPermission(Permissions.BanMembers))
                {
                    errorReason = $"You do not have permission to ban members!";
                    return(false);
                }
                if (user.IsAbove(bot))
                {
                    errorReason = $"{target.Mention} has a role {user.GetHighestRoleMention()} that is above mine, and I cannot ban them!";
                    return(false);
                }
                errorReason = null;
                return(true);
            }

            var userBannedEmbed = new DiscordEmbedBuilder()
                                  .WithAuthorExtension(ctx.Member.DisplayName, ctx.Member.AvatarUrl)
                                  .WithTitle($"You've been banned from {ctx.Guild.Name}!")
                                  .AddField("Reason:", $"{reason}")
                                  .AddFooter(ctx)
                                  .WithColor(new DiscordColor("#0019bd"));

            var(name, url) = ctx.GetAuthor();
            var logEmbed = new DiscordEmbedBuilder()
                           .WithAuthorExtension(name, url)
                           .WithColor(DiscordColor.SpringGreen)
                           .WithDescription($":hammer: {ctx.Member.Mention} banned {target.Mention}!")
                           .AddField("Infraction occured:", DateTime.UtcNow.ToString("dd/MM/yy - HH:mm UTC"))
                           .AddField("Reason:", reason).AddFooter(ctx);

            try
            {
                await DMCommand.DM(ctx, target, userBannedEmbed);
            }
            finally
            {
                await ctx.Guild.BanMemberAsync(user, 7, reason);

                var sendChannel = ctx.Guild.GetChannel(ServerConfigurationManager.LocalConfiguration[ctx.Guild.Id].LoggingChannel) ?? ctx.Channel;
                ServerConfigurationManager.LocalConfiguration[ctx.Guild.Id].BannedMembers.Add(new BannedMember(user.Id, reason));
                await sendChannel.SendMessageAsync(embed : logEmbed);
            }
        }
Пример #5
0
        public async Task Kick(CommandContext ctx, DiscordMember user, [RemainingText] string reason = "Not Given.")
        {
            await ctx.Message.DeleteAsync();

            var bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id);

            if (!ctx.Member.HasPermission(Permissions.KickMembers) && !ctx.Member.IsOwner)
            {
                if (!ctx.Member.HasPermission(Permissions.Administrator))
                {
                    await ctx.RespondAsync("Sorry, only moderators and administrators are allowed to kick people.");
                }
                return;
            }



            //var userRole = user.Roles.Last();

            if (user.IsAbove(bot))
            {
                var    isBot   = user == bot;
                var    isOwner = user == ctx.Guild.Owner;
                var    isMod   = user.HasPermission(Permissions.KickMembers);
                var    isAdmin = user.HasPermission(Permissions.Administrator);
                string errorReason;
                _ = user.IsAbove(bot) switch
                {
                    true when isBot => errorReason = "I wish I could kick myself, but I sadly cannot.",
                              true when isOwner => errorReason = $"I can't kick the owner ({user.Mention}) out of their own server!",
                              true when isMod => errorReason = $"I can't kick {user.Mention}! They're a moderator! ({user.Roles.Last().Mention})",
                              true when isAdmin => errorReason = $"I can't kick {user.Mention}! They're an admin! ({user.Roles.Last().Mention})",

                              _ => errorReason = "`ROLE_CHECK_NULL_REASON.` That's all I know."
                };

                await ctx.RespondAsync(embed : EmbedHelper.CreateEmbed(ctx, errorReason, DiscordColor.Red));
            }
            else
            {
                var embed = new DiscordEmbedBuilder(EmbedHelper.CreateEmbed(ctx, $"You've been kicked from {ctx.Guild.Name}!", "")).AddField("Reason:", reason);


                try
                {
                    await DMCommand.DM(ctx, user, embed);
                }
                catch (InvalidOperationException invalidop)
                {
                    ctx.Client.DebugLogger.LogMessage(LogLevel.Error, "Silk!", invalidop.Message, DateTime.Now, invalidop);
                }

                await ctx.Member.RemoveAsync(reason);

                ServerConfigurationManager.LocalConfiguration.TryGetValue(ctx.Guild.Id, out var guildConfig);
                var logChannelID    = guildConfig?.LoggingChannel;
                var logChannelValue = logChannelID ?? ctx.Channel.Id;
                await ctx.Client.SendMessageAsync(await ServerInfo.Instance.ReturnChannelFromID(ctx, logChannelValue),
                                                  embed : new DiscordEmbedBuilder()
                                                  .WithAuthor(ctx.Member.DisplayName, "", ctx.Member.AvatarUrl)
                                                  .WithColor(DiscordColor.SpringGreen)
                                                  .WithDescription($":boot: Kicked {user.Mention}! (User notified with direct message)")
                                                  .WithFooter("Silk")
                                                  .WithTimestamp(DateTime.Now));
            }
        }