示例#1
0
        private static void Watchdog_UserMatchListUpdated(object source, APIWatchdogMatchUpdateEventArgs args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("New match on " + args.User.PUBGName + "'s account! The new match id is: " + args.MatchID);


            Console.ReadLine();


            API               pubgapi      = new API(Environment.GetEnvironmentVariable("API_KEY", EnvironmentVariableTarget.User));
            APIRequest        matchrequest = pubgapi.RequestMatch(args.MatchID, PlatformRegionShard.PC_NA);
            DiscordWebhooks   webhooks     = new DiscordWebhooks("");
            DiscordEmbedField kills        = new DiscordEmbedField();
            DiscordEmbedField heals        = new DiscordEmbedField();
            DiscordEmbedField winplace     = new DiscordEmbedField();
            DiscordEmbedField headshotkill = new DiscordEmbedField();
            DiscordEmbedField longestkill  = new DiscordEmbedField();
            DiscordEmbedField killstreak   = new DiscordEmbedField();

            foreach (APIPlayer player in matchrequest.Match.PlayerList)
            {
                if (player.PlayerId == args.User.AccountID)
                {
                    kills = new DiscordEmbedField()
                    {
                        Name = "Kills", Value = player.Kills.ToString(), Inline = true
                    };
                    killstreak = new DiscordEmbedField()
                    {
                        Name = "Kill Streak", Value = player.KillStreaks.ToString(), Inline = true
                    };
                    longestkill = new DiscordEmbedField()
                    {
                        Name = "Longest Kill", Value = player.LongestKill.ToString() + " m.", Inline = true
                    };
                    headshotkill = new DiscordEmbedField()
                    {
                        Name = "Headshot Kills", Value = player.HeadshotKills.ToString(), Inline = true
                    };
                    heals = new DiscordEmbedField()
                    {
                        Name = "Heals", Value = player.Heals.ToString(), Inline = true
                    };
                    winplace = new DiscordEmbedField()
                    {
                        Name = "Win Place", Value = player.WinPlace.ToString(), Inline = true
                    };
                }
            }
            DiscordembedAuthor author = new DiscordembedAuthor()
            {
                Name = "", URL = "", Icon_URL = ""
            };

            webhooks.MessageChannel(args.User.PUBGName + "'s Most Recent Match", matchrequest.Match.Gamemode + " on " + matchrequest.Match.MapName, author, new List <DiscordEmbedField>()
            {
                kills, heals, winplace, killstreak, longestkill, headshotkill
            }, "", 231, 163, 54);
            Console.ForegroundColor = ConsoleColor.White;
        }
示例#2
0
        /// <summary>
        /// Gets a column for a page
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public DiscordEmbedField GetColumnForPage(string title, int page)
        {
            if (page <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(page));
            }
            else if (string.IsNullOrEmpty(title))
            {
                throw new ArgumentNullException(nameof(title));
            }

            lock (SyncRoot)
            {
                if (!_fields.ContainsKey(title))
                {
                    return(null);
                }

                EmbedFieldInfo efi    = _fields[title];
                string         column = efi.ToString((page - 1) * 10, 10);


                Type et = typeof(DiscordEmbedField);
                ConstructorInfo[] constructors = et.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
                ConstructorInfo   constructor  = constructors[0];

                DiscordEmbedField def = (DiscordEmbedField)constructor.Invoke(null);
                def.Name   = title;
                def.Value  = column;
                def.Inline = true;

                return(def);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            DiscordWebhooks webhooks = new DiscordWebhooks("https://discordapp.com/api/webhooks/433824702826283018/8l0sO7fOsl0wETFd2wGMbfshsiPb58da_3mwRYr5uJuL11xE9406cxl5jFy0-TYArLkO");

            webhooks.MessageChannel("mems");
            DiscordEmbedField field = new DiscordEmbedField()
            {
                Name = "name1", Value = "val", Inline = true
            };
            DiscordEmbedField field2 = new DiscordEmbedField()
            {
                Name = "name13", Value = "2val", Inline = true
            };
            DiscordembedAuthor author = new DiscordembedAuthor()
            {
                Name = "kitten", URL = "https://gist.github.com/Birdie0/78ee79402a4301b1faf412ab5f1cdcf9", Icon_URL = "http://icons.iconarchive.com/icons/paomedia/small-n-flat/256/sign-check-icon.png"
            };

            webhooks.MessageChannel("title", "desc", author, new List <DiscordEmbedField>()
            {
                field, field2
            }, "", 255, 255, 255, new DiscordEmbedFooter()
            {
                Text = "Footer", Icon_URL = ""
            });
            Console.WriteLine("Done");
            Console.ReadLine();
        }
示例#4
0
 public static EmbedFieldDTO FromDiscord(DiscordEmbedField field)
 {
     return(new()
     {
         Name = field.Name,
         Value = field.Value,
         Inline = field.Inline
     });
 }
示例#5
0
        public async Task About(CommandContext ctx)
        {
            //Shows Typing Indicator
            await ctx.TriggerTypingAsync();

            var embed = new DiscordEmbed
            {
                Title       = "DiscordEvolved",
                Description =
                    "The DiscordEvolved Bot is created by BinaryEvolved with the goal to create a best friend to use when managing your discord servers.\n" +
                    "This bot uses the DiscordSharpPlus Library: https://github.com/NaamloosDT/DSharpPlus (Licensed under MIT)",
                Color = 2162503
            };

            var field1 = new DiscordEmbedField
            {
                Name   = "Version",
                Value  = Properties.Resources.FullVersion,
                Inline = true
            };

            var field2 = new DiscordEmbedField
            {
                Name   = "GitHub",
                Value  = "https://github.com/BinaryEvolved/DiscordEvolved",
                Inline = true
            };

            var thumbnail = new DiscordEmbedThumbnail
            {
                Url = "https://discordapp.com/assets/eadcfed66c2178f6fbcadd4f0d849396.svg"
            };

            embed.Thumbnail = thumbnail;
            embed.Fields.Add(field1);
            embed.Fields.Add(field2);
            await ctx.RespondAsync("", false, embed);
        }
示例#6
0
 public EmbedFieldControl(DiscordChannel channel, DiscordEmbedField field)
 {
     InitializeComponent();
     _channel    = channel;
     DataContext = field;
 }
示例#7
0
        private async Task SendHelp(CommandContext ctx, bool listAll = false)
        {
            /*
             * This whole section is more of an example for how I would like the help section to work.
             * Ideally commands could be disable dynamically in a database or server-to-server by server owners
             * Permissions would be checked dynamically and displayed for the user who requested help
             * Any group section that the user doesn't have permissions for would be hidden
             */

            //Declare status emojis
            var check  = DiscordEmoji.FromName(ctx.Client, ":white_check_mark:");
            var x      = DiscordEmoji.FromName(ctx.Client, ":x:");
            var soon   = DiscordEmoji.FromName(ctx.Client, ":clock8:");
            var noPerm = DiscordEmoji.FromName(ctx.Client, ":no_entry:");

            //List Commands
            var embed = new DiscordEmbed()
            {
                Title       = "Help",
                Description = "The following commands available in the bot",
                Fields      = new List <DiscordEmbedField>(),
                Color       = 2162503
            };

            var statusInformation = new DiscordEmbedField
            {
                Inline = false,
                Name   = "Status Information:",
                Value  = $"`{check}`: Command Online and Ready | `{x}`: Command Unavailable\n" +
                         $"`{soon}`: Coming Soon | `{noPerm}`: Invalid Permissions (for user {ctx.Message.Author.Username})"
            };

            var publicCommands = new DiscordEmbedField
            {
                Inline = false,
                Name   = "Public Commands",
                Value  = $"`{check}help` `{check}about` `{check}uptime` `{check}ping` `{soon}whois` `{soon}serverwhois`"
            };

            //Checks Server Owner Permissions (sOp)
            var sOp = noPerm;

            if (ctx.Message.Channel.Guild.Owner.Id == ctx.Message.Author.Id)
            {
                sOp = check;
            }
            var guildOwner = new DiscordEmbedField
            {
                Inline = false,
                Name   = "Server Owner Commands",
                Value  = $"`{sOp}leaveserver`"
            };


            //Checks Bot Owner Command Permissions (oCp)
            var oCp = noPerm;

            if (ctx.Message.Author.Id == ctx.Client.CurrentApplication.Owner.Id)
            {
                oCp = check;
            }
            var ownerCommands = new DiscordEmbedField
            {
                Inline = false,
                Name   = "Bot Owner Only Commands",
                Value  = $"`{oCp}shutdown` `{oCp}disable` `{oCp}enable`"
            };



            embed.Fields.Add(statusInformation);
            embed.Fields.Add(publicCommands);
            if (listAll || sOp == check)
            {
                embed.Fields.Add(guildOwner);
            }
            if (listAll || oCp == check)
            {
                embed.Fields.Add(ownerCommands);
            }

            await ctx.RespondAsync("", false, embed);
        }
示例#8
0
 private void AddFieldToPanel(Panel p, DiscordEmbedField field)
 {
     p.Children.Add(new EmbedFieldControl(_channel, field));
 }
        [Aliases("lastgame")] // alternative names for the command
        public async Task Last(CommandContext ctx, String user)
        {
            // let's trigger a typing indicator to let
            // users know we're working
            await ctx.TriggerTypingAsync();

            // Validate API key
            var api = RiotApi.GetInstance("//API goes here");

            try
            {
                // Get user's Riot information and 10 recent games
                var summoner = api.GetSummoner(Region.na, user);
                var games    = summoner.GetRecentGames();

                try
                {
                    var match = api.GetMatch(Region.na, (long)games[0].GameId);
                }
                catch (RiotSharpException ex) {
                    Console.WriteLine(ex);
                }


                //match.Participants[0].Stats < - How to access stats

                int totalKills = 1;

                foreach (RiotSharp.MatchEndpoint.Participant part in match.Participants)
                {
                    if (part.TeamId == games[0].TeamId)
                    {
                        totalKills += (int)part.Stats.Kills;
                    }
                }

                // Calculate KDR
                var dmg = games[0].Statistics.TotalDamageDealt.ToString();

                float  KDR = (float)games[0].Statistics.ChampionsKilled / (float)games[0].Statistics.NumDeaths;
                string KD  = "```" + "\n" + games[0].Statistics.ChampionsKilled + " / "
                             + games[0].Statistics.NumDeaths + " / "
                             + games[0].Statistics.Assists + " - "
                             + Math.Round(KDR, 2) + " KDR ```";

                // Preparing the embed

                var embed = new DiscordEmbed
                {
                    Title       = user + "'s Last Game Stats" + " (" + games[0].GameSubType + ")",
                    Description = KD,
                    Footer      = new DiscordEmbedFooter
                    {
                        Text = "Copyright © 2017 by A. Webster - all rights reserved."
                    },
                    Url = "https://na.op.gg/summoner/userName="******"Damage / Kill Participation";
                dmgfield.Value = "`" + games[0].Statistics.TotalDamageDealtToChampions.ToString("#,##0") + " damage - "
                                 + (games[0].Statistics.ChampionsKilled / totalKills) + "% Kill Participation"
                                 + "`";

                var towerfield = new DiscordEmbedField();
                towerfield.Name  = "Towers Destroyed";
                towerfield.Value = "`" + games[0].Statistics.TurretsKilled + " - " + Math.Round(((float)games[0].Statistics.TurretsKilled / (float)11), 2) + "% of enemy towers" + "`";

                var genStatsfield = new DiscordEmbedField();
                genStatsfield.Name = "But did you win?";

                string winStatus;
                if (games[0].Statistics.Win)
                {
                    winStatus = "`Yes! Game won at ";
                }
                else
                {
                    winStatus = "`No. Game lost at ";
                }

                genStatsfield.Value = winStatus + Math.Round(games[0].Statistics.TimePlayed.TotalMinutes) + " minutes.`";



                // Add fields to the embed
                embed.Fields.Add(dmgfield);
                embed.Fields.Add(towerfield);
                embed.Fields.Add(genStatsfield);


                // Send the embed to Discord
                await ctx.RespondAsync("", embed : embed);
            }
            catch (RiotSharpException ex)
            {
                ex.ToString();
            }
        }