コード例 #1
0
ファイル: PingRequest.cs プロジェクト: ExAtom/GroundedBot
        async static void Deny(SocketMessage message, ulong id)
        {
            var requests = PingRequests.PullData();

            if (requests.Count(x => x.ID == id) == 0)
            {
                await message.Channel.SendMessageAsync("❌ Unkown ID!");

                return;
            }
            var request = requests.Find(x => x.ID == id);

            var deniedEmbed = new EmbedBuilder()
                              .WithAuthor(author =>
            {
                author
                .WithName("Ping Request")
                .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/782619217055842334/noun_Close_1984788.png");         // Close by Bismillah from the Noun Project
            })
                              .WithDescription(request.Description.Replace("Waiting...", "Denied"))
                              .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                              .WithColor(new Color(0xDD0000)).Build();
            var oldMsg = await((IMessageChannel)Program._client.GetChannel(BaseConfig.GetConfig().Channels.PingRequests)).GetMessageAsync(request.ID);

            await((IUserMessage)oldMsg).ModifyAsync(m => m.Embed = deniedEmbed);

            requests.Remove(request);
            PingRequests.PushData(requests);

            await message.Channel.SendMessageAsync("Request denied");
        }
コード例 #2
0
ファイル: PingRequest.cs プロジェクト: ExAtom/GroundedBot
        async static void Approve(SocketMessage message, ulong id)
        {
            var requests = PingRequests.PullData();

            if (requests.Count(x => x.ID == id) == 0)
            {
                await message.Channel.SendMessageAsync("❌ Unkown ID!");

                return;
            }
            var request = requests.Find(x => x.ID == id);
            var role    = ((SocketGuildChannel)message.Channel).Guild.GetRole(request.RoleID);

            await((IMessageChannel)Program._client.GetChannel(request.ChannelID)).SendMessageAsync(role.Mention);

            var approvedEmbed = new EmbedBuilder()
                                .WithAuthor(author =>
            {
                author
                .WithName("Ping Request")
                .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/782586791831666688/noun_checkmark_737739.png");         // checkmark by Vladimir from the Noun Project
            })
                                .WithDescription(request.Description.Replace("Waiting...", "Approved"))
                                .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                                .WithColor(new Color(0x00DD00)).Build();
            var oldMsg = await((IMessageChannel)Program._client.GetChannel(BaseConfig.GetConfig().Channels.PingRequests)).GetMessageAsync(request.ID);

            await((IUserMessage)oldMsg).ModifyAsync(m => m.Embed = approvedEmbed);

            requests.Remove(request);
            PingRequests.PushData(requests);

            await message.Channel.SendMessageAsync("Request approved");
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: ExAtom/PixelBot
        /// <summary>
        /// Meghatározható típusú logolás a terminálba és a BaseConfigban beállított szobákba.
        /// </summary>
        /// <param name="mode">command, rankup</param>
        /// <returns></returns>
        public async static Task Log(string mode)
        {
            var message = Recieved.Message;

            Console.Write(DateTime.Now.ToString("yyyy.MM.dd. HH:mm:ss") + " ");
            string output = "";

            switch (mode)
            {
            case "command":
                output = $"Command run - {message.Author.Username}#{message.Author.Discriminator} in #{message.Channel}: {message.Content}";
                break;

            case "rankup":
                var members = Members.PullData();
                output = $"Event - {message.Author.Username}#{message.Author.Discriminator} ranked up: {members[members.IndexOf(members.Find(x => x.ID == message.Author.Id))].Rank + 1}";
                break;

            default:
                return;
            }
            foreach (var id in BaseConfig.GetConfig().Channels.BotTerminal)
            {
                try { await((IMessageChannel)_client.GetChannel(id)).SendMessageAsync(output); }
                catch (Exception) { }
            }
            Console.WriteLine(output);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ExAtom/PixelBot
 /// <summary>
 /// Ellenőrzi, hogy az üzenet bot szobába volt-e küldve.
 /// </summary>
 /// <returns></returns>
 public static bool BotChannel()
 {
     if (BaseConfig.GetConfig().Channels.BotChannel.Contains(Recieved.Message.Channel.Id))
     {
         return(true);
     }
     return(false);
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: ExAtom/PixelBot
 /// <summary>
 /// Ellenőrzi, hogy az üzenetküldőnek van-e megfelelő rangja
 /// </summary>
 /// <param name="allowedRoles"></param>
 /// <returns></returns>
 public static bool HasPerm(List <ulong> allowedRoles)
 {
     foreach (var role in (Recieved.Message.Author as SocketGuildUser).Roles)
     {
         if (allowedRoles.Contains(role.Id) ||
             BaseConfig.GetConfig().Roles.Admin.Contains(role.Id))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: ExAtom/Iqi
        public async Task MainAsync()
        {
            _client = new DiscordSocketClient();
            _client.MessageReceived += MessageHandler;
            _client.Log             += Log;
            var token = BaseConfig.GetConfig().Token;
            await _client.LoginAsync(TokenType.Bot, token);

            await _client.StartAsync();

            await Task.Delay(-1);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: ExAtom/Iqi
 /// <summary>
 /// Ellenőrzi, hogy az üzenetküldő Admin-e.
 /// </summary>
 /// <param name="isOwner">Admin helyett tulajdonost ellenőriz.</param>
 /// <returns></returns>
 public static bool IsAdmin(bool isOwner)
 {
     foreach (var role in (Recieved.Message.Author as SocketGuildUser).Roles)
     {
         if ((role.Permissions.Administrator && !isOwner) ||
             BaseConfig.GetConfig().OwnerID == Recieved.Message.Author.Id)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #8
0
 public async static Task DoEvent(SocketGuildUser user)
 {
     try
     {
         if (user.Guild.Id == BaseConfig.GetConfig().ServerID)
         {
             var members = Members.PullData();
             members.RemoveAt(members.IndexOf(members.Find(x => x.ID == user.Id)));
             Members.PushData(members);
             await Program.Log($"{user.Username}#{user.Discriminator} ({user.Id}) removed from the database");
         }
     }
     catch (Exception) { }
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: ExAtom/Iqi
        /// <summary>
        /// Parancs futtatásának logolása
        /// </summary>
        /// <returns></returns>
        public async static Task LogCommandRun()
        {
            var message = Recieved.Message;

            Console.Write(DateTime.Now.ToString("yyyy.MM.dd. HH:mm:ss") + " ");
            string output = $"Command run - {message.Author.Username}#{message.Author.Discriminator} in #{message.Channel}: {message.Content}";

            foreach (var id in BaseConfig.GetConfig().Terminals)
            {
                try { await((IMessageChannel)_client.GetChannel(id)).SendMessageAsync(output, allowedMentions: AllowedMentions.None); }
                catch (Exception) { }
            }
            Console.WriteLine(output);
        }
コード例 #10
0
        /// <summary>
        /// Error logolás a terminálba és a BaseConfigban beállított szobákba.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public async static Task Log(Exception e)
        {
            var message = Recieved.Message;

            Console.Write(DateTime.Now.ToString("yyyy.MM.dd. HH:mm:ss") + " ");
            string output = $"Error ```\n{e.Message}\n```";

            foreach (var id in BaseConfig.GetConfig().Channels.BotTerminal)
            {
                try { await((IMessageChannel)_client.GetChannel(id)).SendMessageAsync(output, allowedMentions: AllowedMentions.None); }
                catch (Exception) { }
            }
            Console.WriteLine(output);
        }
コード例 #11
0
 public async static Task DoEvent()
 {
     foreach (var id in BaseConfig.GetConfig().Channels.Backups)
     {
         try
         {
             if (id != 0)
             {
                 await((IMessageChannel)Program._client.GetChannel(id)).SendFileAsync(@"Members.json");
                 await Program.Log($"Made a backup in <#{id}>");
             }
         }
         catch (Exception) { }
     }
 }
コード例 #12
0
        public async static Task DoCommand()
        {
            await Program.Log();

            var message = Recieved.Message;

            string[] input = message.Content.Split();

            if (!Program.HasPerm(RequiredRoles) && input.Length < 2)
            {
                await message.Channel.SendMessageAsync("❌ Only members with Ptan+ Budget and above can evaluate math expressions!");

                return;
            }

            try
            {
                Expression expr = new Expression(message.ToString().Replace(input[0], ""));

                var embed = new EmbedBuilder()
                            .WithAuthor(author =>
                {
                    author
                    .WithName("Math evaluation")
                    .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/831126332481470484/noun_Math_3492780.png");         // Math by Clea Doltz from the Noun Project
                })
                            .WithDescription($"Here is your result: **{expr.Evaluate()}**")
                            .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                            .WithColor(new Color(0x65794F)).Build();

                await message.Channel.SendMessageAsync(
                    null,
                    embed : embed)
                .ConfigureAwait(false);
            }
            catch (Exception e)
            {
                await message.Channel.SendMessageAsync("❌ | Sorry, I didn't understand that!");

                foreach (var i in BaseConfig.GetConfig().Channels.BotTerminal)
                {
                    await((IMessageChannel)Program._client.GetChannel(i)).SendMessageAsync($"```{e}```");
                }
            }
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: ExAtom/Iqi
        private Task MessageHandler(SocketMessage message)
        {
            string firstWord = message.Content.Split()[0];
            bool   pong      = message.Author.Id == BaseConfig.GetConfig().BotID&& firstWord == "Pinging...";

            if (pong || !message.Author.IsBot)
            {
                Recieved.Message = message;
            }
            else
            {
                return(Task.CompletedTask);
            }
            if (pong)
            {
                Ping.DoCommand(true);
            }
            if (!message.Content.StartsWith(BaseConfig.GetConfig().Prefix) || message.Author.IsBot)
            {
                return(Task.CompletedTask);
            }

            string command = firstWord.Substring(1, firstWord.Length - 1).ToLower();

            // Commands
            if (Commands.Commands.Aliases.Contains(command) && BotChannel())
            {
                Commands.Commands.DoCommand();
            }
            if (Ping.Aliases.Contains(command) && BotChannel())
            {
                Ping.DoCommand(false);
            }
            if (Restart.Aliases.Contains(command) && BotChannel() && IsAdmin(true))
            {
                Restart.DoCommand();
            }
            if (Test.Aliases.Contains(command) && BotChannel() && IsAdmin(true))
            {
                Test.DoCommand();
            }

            return(Task.CompletedTask);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: ExAtom/PixelBot
        private Task CommandHandler(SocketMessage message)
        {
            if (!message.Content.StartsWith(BaseConfig.GetConfig().Prefix) || message.Author.IsBot)
            {
                return(Task.CompletedTask);
            }
            string firstWord = message.Content.Split()[0];
            string command   = firstWord.Substring(1, firstWord.Length - 1).ToLower();

            if (BotChannel())
            {
                // Dev
                if (Evaluate.Aliases.Contains(command) && HasPerm(Evaluate.AllowedRoles))
                {
                    Evaluate.DoCommand();
                }
                if (Restart.Aliases.Contains(command) && HasPerm(Restart.AllowedRoles))
                {
                    Restart.DoCommand();
                }
                if (Test.Aliases.Contains(command) && HasPerm(Test.AllowedRoles))
                {
                    Test.DoCommand();
                }
                // Fun
                if (Minesweeper.Aliases.Contains(command))
                {
                    Minesweeper.DoCommand();
                }
                // Main
                if (Leaderboard.Aliases.Contains(command))
                {
                    Leaderboard.DoCommand();
                }
                if (Rank.Aliases.Contains(command))
                {
                    Rank.DoCommand();
                }
            }

            return(Task.CompletedTask);
        }
コード例 #15
0
ファイル: AnswerRequest.cs プロジェクト: ExAtom/GroundedBot
        public async static void Approve(SocketMessage message, ulong id, byte score)
        {
            var requests = AnswerRequests.PullData();

            if (requests.Count(x => x.ID == id) == 0)
            {
                await message.Channel.SendMessageAsync("❌ Unkown ID!");

                return;
            }
            var request = requests.Find(x => x.ID == id);

            var approvedEmbed = new EmbedBuilder()
                                .WithAuthor(author =>
            {
                author
                .WithName("Answer Request")
                .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/782586791831666688/noun_checkmark_737739.png");         // checkmark by Vladimir from the Noun Project
            })
                                .WithDescription(request.Description.Replace("Waiting...", $"Approved ({score})"))
                                .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                                .WithColor(new Color(0x00DD00)).Build();
            var oldMsg = await((IMessageChannel)Program._client.GetChannel(BaseConfig.GetConfig().Channels.AnswerRequests)).GetMessageAsync(request.ID);

            await((IUserMessage)oldMsg).ModifyAsync(m => m.Embed = approvedEmbed);

            requests.Remove(request);
            AnswerRequests.PushData(requests);

            var userId  = request.UserID;
            var members = Members.PullData();

            if (members.Count(x => x.ID == userId) == 0)
            {
                members.Add(new Members(userId));
            }
            members[members.IndexOf(members.Find(x => x.ID == userId))].Help += score;
            Members.PushData(members);

            await message.Channel.SendMessageAsync("Request approved");
        }
コード例 #16
0
ファイル: AnswerRequest.cs プロジェクト: ExAtom/GroundedBot
        public async static void Request(SocketMessage message)
        {
            var requests = AnswerRequests.PullData();
            var answerRequestsChannel = (IMessageChannel)Program._client.GetChannel(BaseConfig.GetConfig().Channels.AnswerRequests);

            var responseEmbed = new EmbedBuilder()
                                .WithAuthor(author =>
            {
                author
                .WithName("Answer Request Sent")
                .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/782963424191447061/noun_comment_3266585.png");         // comment by Larea from the Noun Project
            })
                                .WithDescription($"{message.Author.Mention}\nYour request will be reviewed soon")
                                .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                                .WithColor(new Color(0x7289DA)).Build();
            var response = await message.Channel.SendMessageAsync(null, embed : responseEmbed);

            var embedMessage = await answerRequestsChannel.SendMessageAsync(null, embed : new EmbedBuilder().WithDescription("Embed").Build());

            var requestEmbed = new EmbedBuilder()
                               .WithAuthor(author =>
            {
                author
                .WithName("Answer Request")
                .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/782886030638055464/noun_Plus_1809808.png");         // Plus by sumhi_icon from the Noun Project
            })
                               .WithDescription($"{message.Author.Mention} requested to review their answer in <#{message.Channel.Id}>.\nStatus: **Waiting...**\n\n Request's link:\n https://discord.com/channels/{((SocketGuildChannel)message.Channel).Guild.Id}/{message.Channel.Id}/{response.Id} \n\nID: `{embedMessage.Id}`")
                               .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name).Build();
            await embedMessage.ModifyAsync(m => m.Embed = requestEmbed);

            var mention = await answerRequestsChannel.SendMessageAsync(((SocketGuildChannel)message.Channel).Guild.GetRole(782965011047514162).Mention); // AnswerRequest role pingelése a moderátorok értesítéséért.

            await message.Channel.DeleteMessageAsync(message);

            await answerRequestsChannel.DeleteMessageAsync(mention);

            requests.Add(new AnswerRequests(embedMessage.Id, message.Author.Id, requestEmbed.Description));
            AnswerRequests.PushData(requests);
        }
コード例 #17
0
ファイル: PtanCheck.cs プロジェクト: ExAtom/GroundedBot
        public async static Task DoEvent()
        {
            var members = Members.PullData();

            for (int i = 0; i < members.Count; i++)
            {
                DateTime date = DateTime.Now;
                try { date = DateTime.ParseExact(members[i].PPlusDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); }
                catch (Exception) { }
                if (date < DateTime.Now && members[i].PPlusDate != "")
                {
                    members[i].PPlusDate = "";
                    var user = Program._client.GetGuild(830806387956514826).GetUser(members[i].ID);
                    foreach (var role in user.Roles)
                    {
                        if (!BaseConfig.GetConfig().Roles.Mod.Contains(role.Id))
                        {
                            if (BaseConfig.GetConfig().Roles.PtanB.Contains(role.Id))
                            {
                                await user.RemoveRoleAsync(role);
                            }
                            if (BaseConfig.GetConfig().Roles.PtanS.Contains(role.Id))
                            {
                                await user.RemoveRoleAsync(role);
                            }
                            if (BaseConfig.GetConfig().Roles.PtanP.Contains(role.Id))
                            {
                                await user.RemoveRoleAsync(role);
                            }
                        }
                    }
                    await Program.Log($"{user.Username}#{user.Discriminator}'s Ptan+ subscription has expired");

                    Members.PushData(members);
                }
            }
        }
コード例 #18
0
ファイル: Xp.cs プロジェクト: ExAtom/GroundedBot
        public async static Task DoEvent()
        {
            var message = Recieved.Message;

            if (((SocketGuildChannel)message.Channel).Guild.Id != 642864087088234506)
            {
                return;
            }

            bool isSpam = false;

            try
            {
                var lastMessage = (await message.Channel.GetMessagesAsync(10).FlattenAsync()).Where(x => x.Author.Id == message.Author.Id).ElementAt(1);
                isSpam = lastMessage.Content == message.Content || (message.CreatedAt.DateTime - lastMessage.CreatedAt.DateTime).Seconds < 5;
            }
            catch (Exception) { }

            if (message.Content.Length == 1 ||
                isSpam ||
                BaseConfig.GetConfig().Channels.BotChannel.Contains(message.Channel.Id))
            {
                return;
            }

            var members     = Members.PullData();
            int memberIndex = Members.GetMemberIndex(members, message.Author.Id.ToString());

            if (memberIndex == -1)
            {
                memberIndex = members.Count();
                members.Add(new Members(message.Author.Id));
            }
            members[memberIndex].XP++;

            int  xp     = members[memberIndex].XP;
            int  rankup = 30;
            byte rank   = 0;

            while (xp >= rankup)
            {
                rank++;
                xp     -= rankup;
                rankup += rankup / 5;
            }

            if (rank > members[memberIndex].Rank)
            {
                var avatar = message.Author.GetAvatarUrl();
                var embed  = new EmbedBuilder()
                             .WithAuthor(author =>
                {
                    author
                    .WithName("Rank Up")
                    .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/786676132850302996/noun_Graph_2500310.png");         // Graph by Alice Design from the Noun Project
                })
                             .WithDescription($"Congratulations **{message.Author.Mention}**! You ranked up.\nNew rank: **{rank}**")
                             .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                             .WithThumbnailUrl(avatar == null ? message.Author.GetDefaultAvatarUrl() : avatar)
                             .WithColor(new Color(0xFFCC00)).Build();

                var channel = BaseConfig.GetConfig().Channels.LevelUp;
                if (channel != 0)
                {
                    await((IMessageChannel)Program._client.GetChannel(channel)).SendMessageAsync(
                        null,
                        embed: embed)
                    .ConfigureAwait(false);
                }
                await Program.Log($"{message.Author.Username}#{message.Author.Discriminator} ranked up: {rank}");
            }

            if (members[memberIndex].Rank < rank)
            {
                members[memberIndex].Rank = rank;
                members[memberIndex].Floppy++;
            }

            Members.PushData(members);
        }
コード例 #19
0
        public async static void DoEvent()
        {
            var  message = Recieved.Message;
            bool isSpam  = false;

            try
            {
                var lastMessage = (await message.Channel.GetMessagesAsync(10).FlattenAsync()).Where(x => x.Author.Id == message.Author.Id).ElementAt(1);
                isSpam = lastMessage.Content == message.Content || (message.CreatedAt.DateTime - lastMessage.CreatedAt.DateTime).Seconds < 5;
            }
            catch (Exception) { }

            if (message.Content.Length == 1 ||
                isSpam ||
                BaseConfig.GetConfig().Channels.BotChannel.Contains(message.Channel.Id))
            {
                return;
            }

            var members     = Members.PullData();
            int memberIndex = Members.GetMemberIndex(members, message.Author.Id.ToString());

            if (memberIndex == -1)
            {
                memberIndex = members.Count();
                members.Add(new Members(message.Author.Id));
            }
            members[memberIndex].XP++;

            int  xp     = members[memberIndex].XP;
            int  rankup = 30;
            byte rank   = 0;

            while (xp >= rankup)
            {
                rank++;
                xp     -= rankup;
                rankup += rankup / 5;
            }

            if (rank > members[memberIndex].Rank)
            {
                await Program.Log("rankup");

                var embed = new EmbedBuilder()
                            .WithAuthor(author =>
                {
                    author
                    .WithName("Rank Up")
                    .WithIconUrl("https://cdn.discordapp.com/attachments/781164873458778133/781906580559233034/LevelUp.png");
                })
                            .WithDescription($"Congratulations **{message.Author.Mention}**! You ranked up.\nNew rank: **{rank}**")
                            .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                            .WithThumbnailUrl(message.Author.GetAvatarUrl())
                            .WithColor(new Color(0xFFCC00)).Build();

                var channels = BaseConfig.GetConfig().Channels.LevelUp;
                if (channels[0] != 0)
                {
                    foreach (var id in channels)
                    {
                        await((IMessageChannel)Program._client.GetChannel(id)).SendMessageAsync(
                            null,
                            embed: embed)
                        .ConfigureAwait(false);
                    }
                }
            }

            members[memberIndex].Rank = rank;

            Members.PushData(members);
        }
コード例 #20
0
ファイル: PingRequest.cs プロジェクト: ExAtom/GroundedBot
        async static void Request(SocketMessage message, SocketRole role)
        {
            var    requests            = PingRequests.PullData();
            Random r                   = new Random();
            var    pingRequestsChannel = (IMessageChannel)Program._client.GetChannel(BaseConfig.GetConfig().Channels.PingRequests);

            if (Program.HasPerm(PtanProRoles))
            {
                ulong[] allowedRoles =
                {
                    915699684327186452,
                    915699889399271494,
                    642999690140450816,
                    643057615542157325,
                    915700336080085012,
                    915700679895556157,
                    718745058328707144,
                    656935125610790932,
                    656935401889464320,
                    693928850576506962,
                    915700971697504276,
                    848142088579448862,
                    915701267865677904,
                    656934935978049586
                };

                if (allowedRoles.Contains(role.Id))
                {
                    await message.Channel.SendMessageAsync(role.Mention);

                    await message.Channel.DeleteMessageAsync(message);
                }
                else
                {
                    await message.Channel.SendMessageAsync("❌ No, I will not ping that!");
                }
                return;
            }

            var responseEmbed = new EmbedBuilder()
                                .WithAuthor(author =>
            {
                author
                .WithName("Ping Request Sent")
                .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/782336504462049300/noun_At_7133.png");         // At by Márcio Duarte from the Noun Project
            })
                                .WithDescription($"{role.Mention}\nYour request will be reviewed soon")
                                .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                                .WithColor(role.Color).Build();
            var response = await message.Channel.SendMessageAsync(null, embed : responseEmbed);

            var embedMessage = await pingRequestsChannel.SendMessageAsync(null, embed : new EmbedBuilder().WithDescription("Embed").Build());

            var requestEmbed = new EmbedBuilder()
                               .WithAuthor(author =>
            {
                author
                .WithName("Ping Request")
                .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/782886030638055464/noun_Plus_1809808.png");         // Plus by sumhi_icon from the Noun Project
            })
                               .WithDescription($"{message.Author.Mention} requested to ping {role.Mention} in <#{message.Channel.Id}>.\nStatus: **Waiting...**\n\n Request's link:\n https://discord.com/channels/{((SocketGuildChannel)message.Channel).Guild.Id}/{message.Channel.Id}/{response.Id} \n\nID: `{embedMessage.Id}`")
                               .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name).Build();
            await embedMessage.ModifyAsync(m => m.Embed = requestEmbed);

            var mention = await pingRequestsChannel.SendMessageAsync(((SocketGuildChannel)message.Channel).Guild.GetRole(782879567873310740).Mention); // PingRequest role pingelése a moderátorok értesítéséért.

            await message.Channel.DeleteMessageAsync(message);

            await pingRequestsChannel.DeleteMessageAsync(mention);

            requests.Add(new PingRequests(embedMessage.Id, role.Id, message.Channel.Id, requestEmbed.Description));
            PingRequests.PushData(requests);
        }
コード例 #21
0
        public async static Task DoCommand()
        {
            await Program.Log();

            var message = Recieved.Message;

            string[] m = message.Content.Split();

            var commands = new List <Command>();

            // Dev
            commands.Add(new Command("Evaluate", Evaluate.Aliases, Evaluate.Description, Evaluate.Usages, Evaluate.Permission, "Dev", Evaluate.Trello));
            commands.Add(new Command("Ping", Ping.Aliases, Ping.Description, Ping.Usages, Ping.Permission, "Dev", Ping.Trello));
            commands.Add(new Command("Restart", Restart.Aliases, Restart.Description, Restart.Usages, Restart.Permission, "Dev", Restart.Trello));
            commands.Add(new Command("Test", Test.Aliases, Test.Description, Test.Usages, Test.Permission, "Dev", Test.Trello));
            // Fun
            commands.Add(new Command("Math", MathEval.Aliases, MathEval.Description, MathEval.Usages, MathEval.Permission, "Fun", MathEval.Trello));
            commands.Add(new Command("Minesweeper", Minesweeper.Aliases, Minesweeper.Description, Minesweeper.Usages, Minesweeper.Permission, "Fun", Minesweeper.Trello));
            // Info
            commands.Add(new Command("Commands", Commands.Aliases, Commands.Description, Commands.Usages, Commands.Permission, "Info", Commands.Trello));
            commands.Add(new Command("EmojiList", EmojiList.Aliases, EmojiList.Description, EmojiList.Usages, EmojiList.Permission, "Info", EmojiList.Trello));
            commands.Add(new Command("Leaderboard", Leaderboard.Aliases, Leaderboard.Description, Leaderboard.Usages, Leaderboard.Permission, "Info", Leaderboard.Trello));
            commands.Add(new Command("UserInfo", UserInfo.Aliases, UserInfo.Description, UserInfo.Usages, UserInfo.Permission, "Info", UserInfo.Trello));
            // Mod
            commands.Add(new Command("Placeholder", new string[] { }, "", new string[] { }, "", "Mod", ""));
            // Music
            commands.Add(new Command("Placeholder", new string[] { }, "", new string[] { }, "", "Music", ""));
            // Util
            commands.Add(new Command("AnswerRequest", AnswerRequest.Aliases, AnswerRequest.Description, AnswerRequest.Usages, AnswerRequest.Permission, "Util", AnswerRequest.Trello));
            commands.Add(new Command("PingRequest", PingRequest.Aliases, PingRequest.Description, PingRequest.Usages, PingRequest.Permission, "Util", PingRequest.Trello));
            commands.Add(new Command("Store", Store.Aliases, Store.Description, Store.Usages, Store.Permission, "Util", Store.Trello));

            var embed = new EmbedBuilder()
                        .WithAuthor(author => { author.WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/801852346350174208/noun_Information_405516.png"); }) // Information by Viktor Ostrovsky from the Noun Project
                        .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                        .WithColor(new Color(0x7289DA));

            switch (m.Length)
            {
            case 1:
                embed.WithAuthor(author => { author.WithName("Commands"); });
                embed.WithDescription($"For more information use `{BaseConfig.GetConfig().Prefix}commands [command]`.\n" +
                                      "Official Documentation on [Trello](https://trello.com/b/Ns1WcpEB/groundedbot).");

                var categories = new HashSet <string>();
                foreach (var i in commands)
                {
                    categories.Add(i.Category);
                }

                foreach (var category in categories)
                {
                    string content         = "```\n";
                    var    currentCategory = commands.Where(x => x.Category == category).ToList();
                    for (int j = 0; j < currentCategory.Count(); j++)
                    {
                        content += $"{currentCategory[j].Name}\n";
                    }
                    for (int j = 0; j < commands.GroupBy(x => x.Category).OrderBy(x => x.Count()).Last().Count() - currentCategory.Count(); j++)
                    {
                        content += " \n";
                    }
                    content += "```";
                    embed.AddField(category, content, true);
                }
                await message.Channel.SendMessageAsync(null, embed : embed.Build());

                break;

            case 2:
                List <Command> foundCommands;
                foundCommands = commands.Where(x => x.Aliases.Contains(m[1].ToLower())).ToList();

                if (foundCommands.Count < 1)
                {
                    return;
                }

                foreach (var command in foundCommands)
                {
                    embed.WithAuthor(author => { author.WithName(command.Name); });
                    string content = "";
                    content += $"Category: **{command.Category}**\n" +
                               $"{command.Description}\n" +
                               $"{command.Permission}\n\n" +
                               $"**Usage{(command.Usages.Length > 1 ? "s:\n" : ": ")}**";
                    foreach (var usage in command.Usages)
                    {
                        content += $"`{BaseConfig.GetConfig().Prefix}{usage}`\n";
                    }
                    content += $"\n**Aliases:** ";
                    for (int j = 0; j < command.Aliases.Count(); j++)
                    {
                        content += $"`{command.Aliases[j]}`{(j < command.Aliases.Count() - 1 ? ", " : "\n\n")}";
                    }
                    content += $"Official Documentation on [Trello]({command.Trello}).";
                    embed.WithDescription(content);
                    await message.Channel.SendMessageAsync(null, embed : embed.Build());
                }
                break;

            default:
                await message.Channel.SendMessageAsync("❌ Too many parameters!");

                return;
            }
        }
コード例 #22
0
ファイル: EmojiList.cs プロジェクト: ExAtom/GroundedBot
        public async static Task DoCommand()
        {
            await Program.Log();

            var message = Recieved.Message;

            string[] m = message.Content.Split();
            var      r = new Random();

            var embed = new EmbedBuilder().WithColor(new Color(0xFFDD00));

            if (m.Length > 2)
            {
                await message.Channel.SendMessageAsync("❌ Too many parameters!");
            }
            else if (m.Length == 1)
            {
                embed.WithAuthor(author => { author.WithName("Avaliable emojis"); });
                foreach (var i in Program._client.Guilds.Where(x => x.Name.Contains("Emojis")).OrderBy(x => x.Name))
                {
                    string emojis = "";
                    for (int j = 0; j < 3; j++)
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            emojis += $"{i.Emotes.ElementAt(r.Next(0, i.Emotes.Count()))} ";
                        }
                        emojis += "\n";
                    }
                    embed.AddField(i.Name, emojis, true);
                }
                embed.WithDescription($"For more use `{BaseConfig.GetConfig().Prefix}emojilist [category]`");
            }
            else
            {
                SocketGuild server;
                try
                {
                    server = Program._client.Guilds.First(x => x.Name.ToLower() == m[1].ToLower());
                    embed.WithAuthor(author => { author.WithName(server.Name); });
                }
                catch (Exception) { return; }
                if (server == null)
                {
                    return;
                }
                var emotes         = server.Emotes.Where(x => !x.Animated).OrderBy(x => x.Name);
                var animatedEmotes = server.Emotes.Where(x => x.Animated).OrderBy(x => x.Name);

                for (int i = 0; i < Math.Ceiling(emotes.Count() / 25.0); i++)
                {
                    string output     = "";
                    int    counter    = 0;
                    int    emoteCount = 0;
                    foreach (var j in emotes.Skip(i * 25))
                    {
                        emoteCount++;
                        counter++;
                        output += counter % 5 == 0 && counter != 0 ? $"{j}\n" : j.ToString();
                        if (emoteCount >= 25)
                        {
                            break;
                        }
                    }
                    embed.AddField("Emotes", output, true);
                }
                for (int i = 0; i < Math.Ceiling(animatedEmotes.Count() / 25.0); i++)
                {
                    string output     = "";
                    int    counter    = 0;
                    int    emoteCount = 0;
                    foreach (var j in animatedEmotes.Skip(i * 25))
                    {
                        emoteCount++;
                        counter++;
                        output += counter % 5 == 0 && counter != 0 ? $"{j}\n" : j.ToString();
                        if (emoteCount >= 25)
                        {
                            break;
                        }
                    }
                    embed.AddField("Animated", output, true);
                }
                embed.WithDescription($"[Server Invite]({server.GetInvitesAsync().Result.FirstOrDefault().Url})");
            }

            embed.WithFooter(((SocketGuildChannel)message.Channel).Guild.Name);
            await message.Channel.SendMessageAsync(null, embed : embed.Build());
        }
コード例 #23
0
        private Task MessageHandler(SocketMessage message)
        {
            string firstWord = message.Content.Split()[0];
            bool   pong      = message.Author.Id == _client.CurrentUser.Id && firstWord == "Pinging...";

            if (pong || (!message.Author.IsBot && !message.Author.IsWebhook))
            {
                Recieved.Message = message;
            }
            else
            {
                return(Task.CompletedTask);
            }

            try
            {
                // Events
                BotMention.DoEvent().Wait();
                Emojify.DoEvent().Wait();
                Xp.DoEvent().Wait();

                if (pong)
                {
                    Ping.DoCommand(true).Wait();
                }
                if (!message.Content.StartsWith(BaseConfig.GetConfig().Prefix) || message.Author.IsBot)
                {
                    return(Task.CompletedTask);
                }

                string command = firstWord.Substring(1, firstWord.Length - 1).ToLower();

                // Commands
                // Dev
                if (Evaluate.Aliases.Contains(command) && HasPerm(Evaluate.AllowedRoles))
                {
                    Evaluate.DoCommand().Wait();
                }
                if (Ping.Aliases.Contains(command) && BotChannel())
                {
                    Ping.DoCommand(false).Wait();
                }
                if (Restart.Aliases.Contains(command) && BotChannel() && HasPerm(Restart.AllowedRoles))
                {
                    Restart.DoCommand().Wait();
                }
                if (Test.Aliases.Contains(command) && BotChannel() && HasPerm(Test.AllowedRoles))
                {
                    Test.DoCommand().Wait();
                }
                // Fun
                if (Minesweeper.Aliases.Contains(command) && BotChannel())
                {
                    Minesweeper.DoCommand().Wait();
                }
                if (MathEval.Aliases.Contains(command) && BotChannel())
                {
                    MathEval.DoCommand().Wait();
                }
                // Info
                if (Commands.Commands.Aliases.Contains(command) && BotChannel())
                {
                    Commands.Commands.DoCommand().Wait();
                }
                if (EmojiList.Aliases.Contains(command) && BotChannel())
                {
                    EmojiList.DoCommand().Wait();
                }
                if (Leaderboard.Aliases.Contains(command) && BotChannel())
                {
                    Leaderboard.DoCommand().Wait();
                }
                if (UserInfo.Aliases.Contains(command) && BotChannel())
                {
                    UserInfo.DoCommand().Wait();
                }
                // Util
                if (AnswerRequest.Aliases.Contains(command))
                {
                    AnswerRequest.DoCommand().Wait();
                }
                if (PingRequest.Aliases.Contains(command))
                {
                    PingRequest.DoCommand().Wait();
                }
                if (Store.Aliases.Contains(command) && BotChannel())
                {
                    Store.DoCommand().Wait();
                }
            }
            catch (Exception e)
            {
                foreach (var i in BaseConfig.GetConfig().Channels.BotTerminal)
                {
                    ((IMessageChannel)_client.GetChannel(i)).SendMessageAsync($"```{e}```");
                }
            }
            return(Task.CompletedTask);
        }
コード例 #24
0
        public static async Task DoEvent()
        {
            var   message = Recieved.Message;
            ulong id      = Program._client.CurrentUser.Id;

            if (!((message.Content == $"<@!{id}>" || message.Content == $"<@{id}>") && Program.BotChannel()))
            {
                return;
            }
            char   prefix         = BaseConfig.GetConfig().Prefix;
            string responseString = "";

            List <EmbedFieldBuilder> fieldBuilders = new List <EmbedFieldBuilder>();
            Embed contEmbed;

            using (var httpClient = new HttpClient())
            {
                using (var request = new HttpRequestMessage(new HttpMethod("GET"), BaseConfig.GetConfig().GithubRepoUrl))
                {
                    var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes($"username:{BaseConfig.GetConfig().GithubToken}"));
                    request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}");
                    request.Headers.TryAddWithoutValidation("Accept", "application/vnd.github.v3+json");

                    request.Headers.UserAgent.Add(new ProductInfoHeaderValue("GroundedBot", "1.0"));
                    request.Headers.UserAgent.Add(new ProductInfoHeaderValue("(+https://github.com/ExAtom/GroundedBot)"));

                    var response = httpClient.SendAsync(request).Result;
                    using (StreamReader reader = new StreamReader(response.Content.ReadAsStream()))
                    {
                        responseString = reader.ReadToEnd();
                    }
                }
            }
            try
            {
                //looping through the response of the GitHub API
                JArray Response = JArray.Parse(responseString);
                foreach (JObject Contributor in Response)
                {
                    fieldBuilders.Add(new EmbedFieldBuilder().WithIsInline(false)
                                      .WithName(Contributor["login"].ToString())
                                      .WithValue(Contributor["html_url"].ToString()));
                }
            }
            catch (Exception e)
            {
                foreach (var i in BaseConfig.GetConfig().Channels.BotTerminal)
                {
                    await((IMessageChannel)Program._client.GetChannel(i)).SendMessageAsync($"```{e}```");
                    await((IMessageChannel)Program._client.GetChannel(i)).SendMessageAsync($"```{responseString.Substring(0, 1994)}```");
                }
            }

            if (fieldBuilders.Count == 0)
            {
                contEmbed = new EmbedBuilder()
                            .WithAuthor(author =>
                {
                    author
                    .WithName("Contributors of the GroundedBot project")
                    .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/801852346350174208/noun_Information_405516.png");     // Information by Viktor Ostrovsky from the Noun Project
                })
                            .WithDescription("Cannot communicate to the GitHub API :cry:")
                            .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                            .WithColor(new Color(0x7289DA)).Build();
            }
            else
            {
                contEmbed = new EmbedBuilder()
                            .WithAuthor(author =>
                {
                    author
                    .WithName("Contributors of the GroundedBot project")
                    .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/801852346350174208/noun_Information_405516.png");     // Information by Viktor Ostrovsky from the Noun Project
                })
                            .WithFields(fieldBuilders)
                            .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                            .WithColor(new Color(0x7289DA)).Build();
            }

            var infoEmbed = new EmbedBuilder()
                            .WithAuthor(author =>
            {
                author
                .WithName("Information about the Bot")
                .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/801852346350174208/noun_Information_405516.png");         // Information by Viktor Ostrovsky from the Noun Project
            })
                            .WithDescription($"" +
                                             $"Hi, I'm the main Bot of the **ProgramTan** server! I have many features, you can see them with `{prefix}commands`.\n" +
                                             $"My prefix is: `{prefix}`\n" +
                                             $"Github repository: https://github.com/ExAtom/GroundedBot \n" +
                                             $"Trello board: https://trello.com/b/Ns1WcpEB/groundedbot")
                            .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                            .WithColor(new Color(0x7289DA)).Build();

            if ((message.Content == $"<@!{id}>" || message.Content == $"<@{id}>") && Program.BotChannel())
            {
                await message.Channel.SendMessageAsync(
                    null,
                    embed : infoEmbed)
                .ConfigureAwait(false);

                await message.Channel.SendMessageAsync(
                    null,
                    embed : contEmbed)
                .ConfigureAwait(false);
            }
        }
コード例 #25
0
 protected T GetConfig <T>() where T : BaseConfig
 {
     return(BaseConfig.GetConfig <T>(this.ConfigReader, this.ConfigOverrides, this.ConfigFileOverride, this.ConfigNames));
 }
コード例 #26
0
        public async static Task DoCommand()
        {
            await Program.Log();

            var message = Recieved.Message;

            string[] m       = message.Content.Split();
            var      members = Members.PullData();
            var      items   = Items.PullData();
            string   output  = "";

            if (m.Length == 1)
            {
                output += $"Buying something works like this: `{BaseConfig.GetConfig().Prefix}store buy <itemName>`.\n\n";

                foreach (var i in items)
                {
                    output += $"**{i.Name}** - **{i.Price}**:floppy_disk:{(i.Type == "ptan+" ? "/month" : "")}\n" +
                              $"*{i.Description}*\n" +
                              $"__You get:__\n";
                    foreach (var j in i.YouGet)
                    {
                        output += $"­ - {j}\n";
                    }
                    output += "\n";
                }
                if (items.Count == 0)
                {
                    output += "Wow, such empty!";
                }

                var embed = new EmbedBuilder()
                            .WithAuthor(author =>
                {
                    author
                    .WithName("Store")
                    .WithIconUrl("https://cdn.discordapp.com/attachments/782305154342322226/808302834738135060/noun_Store_840490.png");         // Store by Gregor Cresnar from the Noun Project
                })
                            .WithDescription(output)
                            .WithFooter(((SocketGuildChannel)message.Channel).Guild.Name)
                            .WithColor(new Color(0x067BCE)).Build();
                await message.Channel.SendMessageAsync(null, embed : embed);
            }
            else if (m[1] == "buy")
            {
                if (m.Length == 2)
                {
                    await message.Channel.SendMessageAsync("Please specify an item you want to buy!");

                    return;
                }

                SocketRole role = null;
                foreach (var i in ((SocketGuildChannel)message.Channel).Guild.GetUser(message.Author.Id).Roles)
                {
                    if (!BaseConfig.GetConfig().Roles.Mod.Contains(i.Id))
                    {
                        if (BaseConfig.GetConfig().Roles.PtanB.Contains(i.Id) ||
                            BaseConfig.GetConfig().Roles.PtanS.Contains(i.Id) ||
                            BaseConfig.GetConfig().Roles.PtanP.Contains(i.Id))
                        {
                            role = i;
                            break;
                        }
                    }
                }

                Members member = members[Members.GetMemberIndex(members, message.Author.Id.ToString())];
                Items   item   = null;
                try { item = items[items.IndexOf(items.Find(x => x.Name.ToLower() == m[2].ToLower()))]; }
                catch (Exception) { await message.Channel.SendMessageAsync("❌ Unkown item!"); }

                if (item == null)
                {
                    await message.Channel.SendMessageAsync("❌ Unkown item!");

                    return;
                }
                if (member.Floppy < item.Price)
                {
                    await message.Channel.SendMessageAsync("❌ You don't have enough :floppy_disk:!");

                    return;
                }
                if (item.Type == "ptan+")
                {
                    if (!((item.Name.ToLower() == "ptan+budget" && role == null) ||
                          (item.Name.ToLower() == "ptan+standard" && (role == null ||
                                                                      !BaseConfig.GetConfig().Roles.PtanB.Contains(role.Id))) ||
                          (item.Name.ToLower() == "ptan+pro" && (role == null ||
                                                                 !BaseConfig.GetConfig().Roles.PtanB.Contains(role.Id) ||
                                                                 !BaseConfig.GetConfig().Roles.PtanS.Contains(role.Id)))))
                    {
                        await message.Channel.SendMessageAsync($"❌ You already have {role.Name}!");

                        return;
                    }
                }
                Purchase(item);
            }
        }