コード例 #1
0
ファイル: TwitchCommands.cs プロジェクト: Solferrun/RazBot2
 private string[] Shoutout(TwitchMessage message)
 {
     if (message.Mentions != null && message.Mentions.Length > 0)
     {
         var lastPlaying = WebTools.GetTwitchEndpointResponse($"game/{message.Mentions[0]}");
         return(new string[] { $"Check out {message.Mentions[0]}'s channel, and give them a follow!" +
                               $"They were last seen playing {lastPlaying} at https://www.twitch.tv/{message.Mentions[0]}" });
     }
     else if (message.Args != null && message.Args.Length > 0)
     {
         var lastPlaying = WebTools.GetTwitchEndpointResponse($"game/{message.Args[0]}");
         return(new string[] { $"Check out {message.Args[0]}'s channel, and give them a follow! " +
                               $"They were last seen playing {lastPlaying} at https://www.twitch.tv/{message.Args[0]}" });
     }
     return(new string[] { "I didn\'t see any mentions, so I\'ll just shoutout myself! RazBot2.0 razCool" });
 }
コード例 #2
0
        public static Dictionary <string, dynamic> GetIntent(string text)
        {
            string baseUrl     = "https://api.wit.ai/message?v=20200730&q=";
            string encodedText = HttpUtility.UrlEncode(text);
            var    url         = baseUrl + encodedText;
            var    headers     = new WebHeaderCollection()
            {
                $"Authorization: Bearer {appToken}"
            };

            JObject response = WebTools.GetJObjectResponse(url, headers: headers);

            Console.WriteLine(response);
            try
            {
                if (response.HasValues && response["intents"].Any())
                {
                    var    responseDict = response.ToObject <Dictionary <string, dynamic> >();
                    var    mainIntent   = responseDict["intents"].First;
                    string description  = mainIntent["name"].ToString();
                    double confidence   = double.Parse(mainIntent["confidence"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                    return(new Dictionary <string, dynamic>()
                    {
                        ["description"] = description,
                        ["confidence"] = confidence
                    });
                }
                else
                {
                    return(new Dictionary <string, dynamic>());
                }
            }
            catch (Exception e)
            {
                BotTools.LogToSessionLogFile(e.ToString());
                return(new Dictionary <string, dynamic>());
            }
        }
コード例 #3
0
ファイル: TwitchCommands.cs プロジェクト: Solferrun/RazBot2
 private string[] GetUptime(TwitchMessage message)
 {
     return(new string[] { "Uptime: " + WebTools.GetTwitchEndpointResponse(endpoint: "uptime/maerictv") });
 }
コード例 #4
0
ファイル: GuildWars.cs プロジェクト: Solferrun/RazBot2
        public static void FetchInventoryData()
        {
            try
            {
                // Fetch NA item data
                var inventoryData = new Dictionary <string, Dictionary <string, dynamic> >()
                {
                    ["na"] = new Dictionary <string, dynamic>(),
                    ["eu"] = new Dictionary <string, dynamic>()
                };

                List <string> naCharacterNames = GetCharacters("na").ToObject <List <string> >();

                foreach (var characterName in naCharacterNames)
                {
                    string encodedCharacterName = characterName.Replace(" ", "%20");

                    JObject upperInventoryData = WebTools.GetJObjectResponse($"{BaseURL}/characters/{encodedCharacterName}/inventory", DefaultHeaders("na"));
                    if (upperInventoryData != null && upperInventoryData.HasValues)
                    {
                        JToken bags = upperInventoryData["bags"];
                        inventoryData["na"][characterName] = new List <Dictionary <string, dynamic> >();

                        foreach (JToken bag in bags)
                        {
                            if (bag.HasValues)
                            {
                                JToken bagContents = bag["inventory"];
                                foreach (JToken item in bagContents)
                                {
                                    inventoryData["na"][characterName].Add(item.ToObject <Dictionary <string, dynamic> >());
                                }
                            }
                        }
                    }
                }

                JArray naSharedBankData      = WebTools.GetJArrayResponse($"{BaseURL}/account/bank", DefaultHeaders("na"));
                JArray naSharedInventoryData = WebTools.GetJArrayResponse($"{BaseURL}/account/inventory", DefaultHeaders("na"));
                JArray naMaterialsData       = WebTools.GetJArrayResponse($"{BaseURL}/account/materials", DefaultHeaders("na"));
                JArray naWalletData          = WebTools.GetJArrayResponse($"{BaseURL}/account/wallet", DefaultHeaders("na"));

                inventoryData["na"]["Shared Bank"]      = naSharedBankData.ToObject <List <Dictionary <string, dynamic> > >();
                inventoryData["na"]["Shared Inventory"] = naSharedInventoryData.ToObject <List <Dictionary <string, dynamic> > >();
                inventoryData["na"]["Materials"]        = naMaterialsData.ToObject <List <Dictionary <string, dynamic> > >();
                inventoryData["na"]["Wallet"]           = naWalletData.ToObject <List <Dictionary <string, dynamic> > >();

                // Fetch EU item data
                List <string> euCharacterNames = GetCharacters("eu").ToObject <List <string> >();

                foreach (var characterName in euCharacterNames)
                {
                    string encodedCharacterName = characterName.Replace(" ", "%20");

                    JObject upperInventoryData = WebTools.GetJObjectResponse($"{BaseURL}/characters/{encodedCharacterName}/inventory", DefaultHeaders("eu"));
                    if (upperInventoryData != null && upperInventoryData.HasValues)
                    {
                        JToken bags = upperInventoryData["bags"];
                        inventoryData["eu"][characterName] = new List <Dictionary <string, dynamic> >();

                        foreach (JToken bag in bags)
                        {
                            if (bag.HasValues)
                            {
                                JToken bagContents = bag["inventory"];
                                foreach (JToken item in bagContents)
                                {
                                    inventoryData["eu"][characterName].Add(item.ToObject <Dictionary <string, dynamic> >());
                                }
                            }
                        }
                    }
                }

                JArray euSharedBankData      = WebTools.GetJArrayResponse($"{BaseURL}/account/bank", DefaultHeaders("eu"));
                JArray euSharedInventoryData = WebTools.GetJArrayResponse($"{BaseURL}/account/inventory", DefaultHeaders("eu"));
                JArray euMaterialsData       = WebTools.GetJArrayResponse($"{BaseURL}/account/materials", DefaultHeaders("eu"));
                JArray euWalletData          = WebTools.GetJArrayResponse($"{BaseURL}/account/wallet", DefaultHeaders("eu"));

                inventoryData["eu"]["Shared Bank"]      = euSharedBankData.ToObject <List <Dictionary <string, dynamic> > >();
                inventoryData["eu"]["Shared Inventory"] = euSharedInventoryData.ToObject <List <Dictionary <string, dynamic> > >();
                inventoryData["eu"]["Materials"]        = euMaterialsData.ToObject <List <Dictionary <string, dynamic> > >();
                inventoryData["eu"]["Wallet"]           = euWalletData.ToObject <List <Dictionary <string, dynamic> > >();

                BotTools.WriteToJson(inventoryData, "resources\\inventory_data");
            }
            catch (NullReferenceException e)
            {
                BotTools.LogToSessionLogFile(e.ToString());
            }
        }
コード例 #5
0
ファイル: GuildWars.cs プロジェクト: Solferrun/RazBot2
 private static JArray GetCharacters(string region = "na")
 {
     return(WebTools.GetJArrayResponse($"{BaseURL}/characters", headers: DefaultHeaders(region)));
 }