Example #1
0
        private async Task SocketClientOnUserJoined(SocketGuildUser arg)
        {
            try
            {
                /*if (arg.Guild.Id == 574595004064989214l)
                 * {
                 *                      await arg.SendMessageAsync("**Welcome to the tmodloader 64bit discord!**\n" +
                 *                                                               "If you have any issue, first consult the following documentation. If you still have issue, you can go in #support to report your issue and people will attempt to help you in a short delay.\n" +
                 *                                                               "**Regular tModLoader github wiki** : <https://github.com/blushiemagic/tModLoader/wiki>\r\n" +
                 *                                                               "**tModLoader FNA github repository** : <https://github.com/Dradonhunter11/tModLoader/tree/x64>\r\n" +
                 *                                                               "**tModLoader broken mod list** : <https://docs.google.com/document/d/1D9pQpr3Hm5wGvP4kI7DKIhMUbS6T9fshkp8Yv4iJx-A/>\r\n\n" +
                 *                                                               "If you come from fury tutorial and it ask you for registry key or you don't see some mod, pls consult <#574702758133760010> and update your game\r\n" +
                 *                                                               "If you are getting `System.IO.IOException: Cannot create a file when that file already exists.`, delete the content of your log folder at `%UserProfile%\\My Games\\Terraria\\ModLoader`\r\n" +
                 *                                           "Terra custom do not work with this as it is a 32bit app\r\n" +
                 *                                           "If you get none of these issue above, please send your log file, otherwise we won't help you (require log policy)");
                 * }*/

                EmbedBuilder builder = new EmbedBuilder();
                builder.WithAuthor(arg.Username);
                builder.WithThumbnailUrl(arg.GetAvatarUrl());
                builder.WithColor(Color.Green);
                builder.AddField(BotUtils.CreateEmbdedField("User", arg.Username));
                await GuildConfigManager.instance.Log(Bot.Instance.socket.GetGuild(arg.Guild.Id).GetTextChannel(GuildConfigManager.instance.config[arg.Guild.Id].loggingChannelID), "New user joined the server", builder.Build());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Example #2
0
        public async Task PriceCheck([Remainder] string name = null)
        {
            try
            {
                string       uri          = $"https://api.warframe.market/v1/items/{name.Replace(" ", "_").ToLower()}/statistics";
                string       result       = Get(uri);
                string       parsedResult = json.GetJArray(json.GetInternalObject(json.GetInternalObject(json.GetInternalObject(result, "payload"), "statistics_closed"), "48hours"))[0].ToString();
                EmbedBuilder builder      = new EmbedBuilder();
                builder.WithAuthor("Warframe.market API");
                builder.WithTitle(name.ToUpper());
                builder.AddField(BotUtils.CreateEmbdedField("Date",
                                                            json.GetInternalValue(parsedResult, "datetime")));
                builder.AddField(BotUtils.CreateEmbdedField("Quantity Sold",
                                                            json.GetInternalValue(parsedResult, "volume"), false));
                builder.AddField(BotUtils.CreateEmbdedField("Minimum Price",
                                                            json.GetInternalValue(parsedResult, "min_price")));
                builder.AddField(BotUtils.CreateEmbdedField("Maximum Price",
                                                            json.GetInternalValue(parsedResult, "max_price")));
                builder.AddField(BotUtils.CreateEmbdedField("Average Price",
                                                            json.GetInternalValue(parsedResult, "avg_price")));
                builder.AddField(BotUtils.CreateEmbdedField("Median Price",
                                                            json.GetInternalValue(parsedResult, "median"), false));
                await ReplyAsync(Context.User.Mention, false, builder.Build());
            }
            catch (Exception e)
            {
                await ReplyAsync(
                    "An error happened while doing the request to the Warframe.Market API. Generally caused by the fact you made an error in the name of the item you requested or that no one have sold this item in the last 48 hours.");

                Console.WriteLine(e);
            }
            //json.GetInternalArray(
            //    json.GetInternalObject(json.GetInternalObject(result, "payload"), "statistics_closed"), "48hours");
        }
Example #3
0
        public async Task ProfileInfo()
        {
            IUser        user  = Context.User;
            EmbedBuilder embed = new EmbedBuilder();

            embed.WithImageUrl(user.GetAvatarUrl());
            embed.AddField(BotUtils.CreateEmbdedField("Account creation date", user.CreatedAt.ToString(), false));
            await ReplyAsync(null, false, embed.Build());
        }
Example #4
0
        public async Task GuildInfo()
        {
            EmbedBuilder builder = new EmbedBuilder();

            builder.WithDescription($"{Context.Guild.Name} Info - Generated by DradonBotSharp");
            builder.AddField(BotUtils.CreateEmbdedField("Guild ID", Context.Guild.Id));
            builder.AddField(BotUtils.CreateEmbdedField("Population", Context.Guild.MemberCount));
            builder.AddField(BotUtils.CreateEmbdedField("Channel count", Context.Guild.Channels.Count));
            builder.AddField(BotUtils.CreateEmbdedField("Role amount", Context.Guild.Roles.Count));

            builder.WithColor(Color.Gold);
            builder.WithThumbnailUrl(Context.Guild.IconUrl);

            await ReplyAsync("", false, builder.Build());
        }
Example #5
0
        public async Task AddRectionEvent(Cacheable <IUserMessage, ulong> MessageId, ISocketMessageChannel channel,
                                          SocketReaction reaction)
        {
            var guildChannel = channel as SocketGuildChannel;


            if (reaction.Emote.Name == "⭐" && _json.IsChannelFeatured(channel.Id))
            {
                Console.WriteLine("it's a star!");

                var message = channel.GetMessageAsync(MessageId.Id).Result as IUserMessage;
                try
                {
                    if (_json.MetReactionRequirement(channel.Id, message.Reactions[reaction.Emote].ReactionCount) && !_json.IsAlreadyFeatured(message))
                    {
                        EmbedBuilder       builder = new EmbedBuilder();
                        EmbedAuthorBuilder author  = new EmbedAuthorBuilder();
                        author.Name    = message.Author.Username;
                        author.IconUrl = message.Author.GetAvatarUrl();
                        builder.WithAuthor(author);
                        if (message.Content != "")
                        {
                            builder.AddField(BotUtils.CreateEmbdedField("Message Content", message.Content, false));
                        }
                        if (message.Attachments.Count != 0)
                        {
                            builder.WithImageUrl(message.Attachments.ToList()[0].ProxyUrl);
                        }
                        builder.WithUrl(message.GetJumpUrl());
                        builder.WithTitle("Go to the message");
                        await guildChannel.Guild.GetTextChannel(_json.GetFeaturedChannel(channel.Id))
                        .SendMessageAsync("", false, builder.Build());

                        _json.AddMessageID(channel.Id, message.Id);
                        _json.SaveFeaturedChannelConfig();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Example #6
0
        public async Task Arbitration()
        {
            try
            {
                string       uri          = $"http://arbitrationtracker.tk/api/";
                string       result       = Get(uri);
                string       parsedResult = result;
                EmbedBuilder builder      = new EmbedBuilder();
                builder.WithAuthor("http://arbitrationtracker.tk/");
                builder.WithTitle("Current Arbitration");
                builder.WithThumbnailUrl(
                    "http://content.warframe.com/MobileExport/Lotus/Materials/Emblems/EliteAlertIcon.png");
                builder.AddField(BotUtils.CreateEmbdedField("Node",
                                                            json.GetInternalValue(parsedResult, "planet") + " - " + json.GetInternalValue(parsedResult, "node")));
                builder.AddField(BotUtils.CreateEmbdedField("Faction",
                                                            json.GetInternalValue(parsedResult, "enemy")));
                builder.AddField(BotUtils.CreateEmbdedField("Mission Type",
                                                            json.GetInternalValue(parsedResult, "type")));

                double   time       = double.Parse(json.GetInternalValue(parsedResult, "startedat").ToString());
                DateTime date       = ConvertFromUnixTimestamp(time);
                string   dateString = $"{date.Year}/{date.Month.ToString("D" + 2)}/{date.Day.ToString("D" + 2)}/{date.Hour.ToString("D"+2)}:{date.Minute.ToString("D" + 2)}:{date.Second.ToString("D" + 2)}";
                builder.AddField(BotUtils.CreateEmbdedField("Start Time",
                                                            dateString, false));

                time       = time + 3600000 * 5;
                date       = ConvertFromUnixTimestamp(time).ToLocalTime();
                dateString = $"{date.Year}/{date.Month.ToString("D" + 2)}/{date.Day.ToString("D" + 2)}/{date.Hour.ToString("D" + 2)}:{date.Minute.ToString("D" + 2)}:{date.Second.ToString("D" + 2)}";
                builder.AddField(BotUtils.CreateEmbdedField("EndTime",
                                                            dateString));

                await ReplyAsync(Context.User.Mention, false, builder.Build());
            }
            catch (Exception e)
            {
                await ReplyAsync(
                    "Sorry, this API is temporarily down.");
            }
            //http://content.warframe.com/MobileExport/Lotus/Materials/Emblems/EliteAlertIcon.png
        }
Example #7
0
        public Embed GetGuildChannelList(IGuild guild)
        {
            try
            {
                string commandText = $"SELECT ChannelName " +
                                     $"FROM channel ch JOIN `discord server` ds ON ch.GuildID = ds.GuildID " +
                                     $"ORDER BY ch.ChannelName ASC";
                MySqlCommand    command       = new MySqlCommand(commandText, _connection);
                MySqlDataReader commandOutput = command.ExecuteReader();

                EmbedBuilder builder = new EmbedBuilder();

                builder.WithDescription($"Channel list for {guild.Name}");


                string channelList = "";

                if (commandOutput.HasRows)
                {
                    while (commandOutput.Read())
                    {
                        channelList += commandOutput.GetString("ChannelName");
                    }
                }

                builder.AddField(BotUtils.CreateEmbdedField("Number of channel", commandOutput.FieldCount));

                commandOutput.Close();
                return(builder.Build());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(null);
        }
        // TODO: Autohastebin .cs or .txt file attachments.
        private async Task HandleCommand(SocketMessage socketMessage)
        {
            // Valid message, no bot, no webhook, and valid channel
            if (!(socketMessage is SocketUserMessage message) ||
                message.Author.IsBot ||
                message.Author.IsWebhook ||
                !(message.Channel is SocketTextChannel channel))
            {
                return;
            }

            var context = new SocketCommandContext(_client, message);

            if (!GuildConfigManager.instance.HasPermission(context.Guild.Id, "HastebinPermission"))
            {
                return;
            }

            string contents              = message.Content;
            bool   shouldHastebin        = false;
            bool   autoDeleteUserMessage = false;
            string extra = "";

            var attachents = message.Attachments;

            if (attachents.Count == 1 && attachents.ElementAt(0) is Attachment attachment)
            {
                if (attachment.Filename.EndsWith(".log") || attachment.Filename.EndsWith(".cs") && attachment.Size < 100000)
                {
                    using (var client = new HttpClient())
                        contents = await client.GetStringAsync(attachment.Url);

                    shouldHastebin = true;
                    extra          = $" `({attachment.Filename})`";
                }
            }

            if (string.IsNullOrWhiteSpace(contents))
            {
                return;
            }

            int count = 0;

            if (!shouldHastebin)
            {
                foreach (char c in contents)
                {
                    if (c == '{')
                    {
                        count++;
                    }
                    if (c == '}')
                    {
                        count++;
                    }
                    if (c == '=')
                    {
                        count++;
                    }
                    if (c == ';')
                    {
                        count++;
                    }
                }
                if (count > 1 && message.Content.Split('\n').Length > 16)
                {
                    shouldHastebin        = true;
                    autoDeleteUserMessage = true;
                }
            }

            if (shouldHastebin)
            {
                string hastebinContent = contents.Trim('`');

                //var msg = await context.Channel.SendMessageAsync("Auto Hastebin in progress");
                using (var client = new HttpClient())
                {
                    HttpContent content = new StringContent(hastebinContent);

                    var response = await client.PostAsync("https://paste.mod.gg/documents", content);

                    string resultContent = await response.Content.ReadAsStringAsync();

                    var match = _HasteKeyRegex.Match(resultContent);

                    if (!match.Success)
                    {
                        return;
                    }



                    string       hasteUrl = $"https://paste.mod.gg/{match.Groups["key"]}.cs";
                    EmbedBuilder builder  = new EmbedBuilder();
                    builder.WithAuthor(context.User.Username);
                    builder.WithColor(Color.DarkBlue);
                    builder.WithThumbnailUrl(context.User.GetAvatarUrl());
                    builder.AddField(BotUtils.CreateEmbdedField("Hastebin URL link", hasteUrl));
                    await context.Channel.SendMessageAsync($"Automatic Hastebin for {message.Author.Username}{extra}\nOriginal Module from Jopojelly", false, builder.Build());

                    if (GuildConfigManager.instance.HasPermission(context.Guild.Id, "LoggingPermission"))
                    {
                        await GuildConfigManager.instance.Log(context, $"{socketMessage.Attachments.First().Filename} has been successfully uploaded to hastebin (Requested by {socketMessage.Author.Username})", builder.Build());
                    }
                    if (autoDeleteUserMessage)
                    {
                        await message.DeleteAsync();
                    }
                }
            }
        }