コード例 #1
0
ファイル: Events.cs プロジェクト: Lygaen/Proty
        public static Task MessageCreated(DiscordClient sender, MessageCreateEventArgs e)
        {
            Task.Run(async() =>
            {
                var cnext = sender.GetCommandsNext();
                var msg   = e.Message;

                // Check if message has valid prefix.
                var dbGuild = await Db.Instance.FetchDbGuildAsync(e.Guild);
                if (dbGuild == null)
                {
                    await e.Channel.SendMessageAsync(MessageUtils.BuildLoading("Adding your guild to the DB..."));
                    await Db.Instance.CreateDbGuild(new DbGuild()
                    {
                        GuildId = e.Guild.Id,
                        Prefix  = "!",
                        Premium = false
                    });
                    Logger.LogInformation($"Added guild \"{e.Guild.Name}\" ({e.Guild.Id}) to the DB !");
                    await e.Channel.SendMessageAsync(MessageUtils.BuildSuccess("Guild added to the DB !"));
                    dbGuild = await Db.Instance.FetchDbGuildAsync(e.Guild);
                }

                var cmdStart = msg.GetStringPrefixLength(dbGuild.Prefix);
                if (cmdStart == -1)
                {
                    return;
                }

                // Retrieve prefix.
                var prefix = msg.Content[..cmdStart];
コード例 #2
0
ファイル: ModeratorCommands.cs プロジェクト: Lygaen/Proty
        public async Task SoftBan(CommandContext ctx, [Description("The member to Soft Ban.")] DiscordMember member, [Description("The reason on why to soft ban this member.")] string reason = "No reason given")
        {
            await member.BanAsync(7, reason : "Proty Soft Ban : " + reason);

            await member.UnbanAsync("Proty Soft Ban : " + reason);

            await ctx.Channel.SendMessageAsync(MessageUtils.BuildSuccess($"Member {member.Mention} ({member.Id}) was soft banned from the server !"));
        }
コード例 #3
0
ファイル: ModeratorCommands.cs プロジェクト: Lygaen/Proty
        public async Task Clear(CommandContext ctx, [Description("The amount of message to delete, will cap at 200.")] int amount = 100)
        {
            try
            {
                await ctx.Channel.DeleteMessagesAsync(await ctx.Channel.GetMessagesAsync(Math.Max(amount, 200)));
            }
            catch (BadRequestException)
            {
                await ctx.Channel.SendMessageAsync(MessageUtils.BuildError($"Couldn't delete all messages, some are older than 14 days (Discord limit when purging)."));

                return;
            }

            await ctx.Channel.SendMessageAsync(MessageUtils.BuildSuccess($"Successfully deleted `{amount}` messages !"));
        }
コード例 #4
0
ファイル: AdministratorCommands.cs プロジェクト: Lygaen/Proty
        public async Task Prefix(CommandContext ctx, [Description("The new prefix.")] string prefix)
        {
            if (prefix.Length > 3)
            {
                await ctx.Channel.SendMessageAsync(MessageUtils.BuildError("Prefix length caps to 3 ! This prefix is too long !"));

                return;
            }

            var guild = await Db.FetchDbGuildAsync(ctx.Guild);

            guild.Prefix = prefix;
            await Db.UpdateDbGuild(guild);

            await ctx.Channel.SendMessageAsync(MessageUtils.BuildSuccess($"Prefix was successfully changed to `{prefix}` !"));
        }
コード例 #5
0
ファイル: InformationCommands.cs プロジェクト: Lygaen/Proty
        public async Task Bug(CommandContext ctx, [Description("The bug explained in detail.")][RemainingText] string bug)
        {
            var client  = new DiscordWebhookClient();
            var webhook = await client.AddWebhookAsync(new Uri("https://discord.com/api/webhooks/852610216922054716/-n7TPmqRYjY_iok0hyHte8AkK4luspZwAZcvunS9yHdzIiXrfEE6PdPou4ypRO_B03Kb"));

            await new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder()
            {
                Title       = "🐛 Bug",
                Description = string.Join(" ", bug),
                Author      = new DiscordEmbedBuilder.EmbedAuthor()
                {
                    IconUrl = ctx.User.AvatarUrl,
                    Name    = ctx.User.Username + "#" + ctx.User.Discriminator
                },
                Color = DiscordColor.Green
            }).SendAsync(webhook);
            await ctx.Channel.SendMessageAsync(MessageUtils.BuildSuccess("Sent the bug !\nAny abuse will be punished..."));
        }
コード例 #6
0
ファイル: ModeratorCommands.cs プロジェクト: Lygaen/Proty
        public async Task Kick(CommandContext ctx, [Description("The member to Kick.")] DiscordMember member, [Description("The reason on why to kick this member.")] string reason = "No reason given")
        {
            await member.RemoveAsync("Proty Kick : " + reason);

            await ctx.Channel.SendMessageAsync(MessageUtils.BuildSuccess($"Member {member.Mention} ({member.Id}) was kicked from the server !"));
        }