public static async Task <string> getImgurUrl(string searchTerm) { List <string> urls = new List <string>(); string t = await WebUtils.httpRequest("https://api.imgur.com/3/gallery/search/?q=" + searchTerm, true); dynamic dynObj = JsonConvert.DeserializeObject(t); foreach (var data in dynObj.data) { string dt = data.link; urls.Add(dt); } return(MasterUtils.getWord(urls)); }
//return content from dictionary public static string getFromRexDB(string username, string id) { string res = string.Empty; if (rexDB.ContainsKey(username) && rexDB[username].ContainsKey(id)) { res = rexDB[username][id]; if (MasterUtils.ContainsAny(res, GlobalVars.REXDB_DISALLOWED_FUNCTIONS)) { res = "Guys I suck! hahaha... Just report me please haha!"; } } else { res = "You have nothing stored here"; } return(res); }
public static string getPossibleCommand(int argCount, string argType = "username") { if (argCount == 0) { return(MasterUtils.getWord(GlobalVars.POSSIBLE_TO_RANDOM_0ARG)); } else if (argCount == 1 && argType == "username") { return(MasterUtils.getWord(GlobalVars.POSSIBLE_TO_RANDOM_1ARG_USERNAME) + " " + getRandomName()); } else if (argCount == 1 && argType == "shortsearch") { return(MasterUtils.getWord(GlobalVars.POSSIBLE_TO_RANDOM_1ARG_SHORTSEARCH) + " " + MasterUtils.getWord(GlobalVars.RANDOM_SHORTSEARCH_TERMS)); } else if (argCount == 1 && argType == "longsearch") { return(MasterUtils.getWord(GlobalVars.POSSIBLE_TO_RANDOM_1ARG_LONGSEARCH) + " " + MasterUtils.getWord(GlobalVars.RANDOM_LONGSEARCH_TERMS) + " " + MasterUtils.sillyName()); } return("error"); }
public static void generateCompany() { string[] nameends = { "Society", "Zoo", "Hospital", "University", "Coorporation", "Charity", "Inc", "Games", "Education", "Construction","Photography", "Pornography" }; int nameendindex = rnd.Next(0, nameends.Length); int risk = rnd.Next(0, 6); int ethicality = rnd.Next(0, 6); int maxinvestment = rnd.Next(20, 300); int maxreward = rnd.Next(105, 220); int duration = rnd.Next(180, 600); companyIndex++; string companyName = MasterUtils.capitalizeFirstChar(MasterUtils.getWord(adjList)) + " " + MasterUtils.capitalizeFirstChar(MasterUtils.getWord(nounList)) + " " + nameends[nameendindex]; Company comp = new Company(companyIndex, companyName, risk, ethicality, maxinvestment, maxreward, duration); companies.Add(comp); allcompanies.Add(comp); //Logger.NewLine("added " + comp.ToString()); }
//Add line to file + update current dictionary //File wont delete existing id's //Load process will simply overwrite so most recent pair survives public static void writeToRexDB(string userName, string id, string content) { if (MasterUtils.ContainsAny(content, new string[] { "!meme" }) && content.Count(x => x == '(') == 3) { int bracketCount = 0; string type = string.Empty; string topText = string.Empty; string botText = string.Empty; for (int i = 0; i < content.Length; i++) { if (content[i] == '(' || content[i] == ')') { bracketCount++; } if (bracketCount == 3) { if (content[i] != '(') { topText += content[i]; } } if (bracketCount == 5) { if (content[i] != '(') { botText += content[i]; } } if (bracketCount == 1) { if (content[i] != ')' && content[i] != '(') { type += content[i]; } } } topText = MasterUtils.processTextForMeme(topText); botText = MasterUtils.processTextForMeme(botText); string final = "https://memegen.link/" + type + "/" + topText + "/" + botText + ".jpg"; content = final; } if (!rexDB.ContainsKey(userName)) { rexDB[userName] = new Dictionary <string, string>(); } if (MasterUtils.ContainsAny(content, GlobalVars.REXDB_DISALLOWED_FUNCTIONS)) { content = "Guys I suck! hahaha... Just report me please haha!"; } if (rexDB[userName].ContainsKey(id)) { rexDB[userName][id] = content; } else { rexDB[userName].Add(id, content); } using (StreamWriter sw = File.AppendText(textPath + "rexdb.txt")) { sw.WriteLine(userName + 'ㄱ' + id + 'ㄱ' + content); } }
//Discontinued... THIS IS PAYED SERVICE WITH NO FREE QUOTA WTF (smh google) // public static async Task<string> RexTranslate(string originalStr) //{ // var service = new TranslateService(new BaseClientService.Initializer() // { // ApiKey = GlobalVars.GOOGLE_TRANSLATE_KEY, // ApplicationName = "Translate API Sample" // }); // string[] toTranslate = new string[1]; // toTranslate[0] = originalStr; // var response = await service.Translations.List(toTranslate, "ko").ExecuteAsync(); // var translations = new List<string>(); // foreach (TranslationsResource translation in response.Translations) // { // translations.Add(translation.TranslatedText); // Console.WriteLine("translation :" + translation.TranslatedText); // } // return translations.ElementAt<string>(0); //} public static async Task <string> YoutubeTest(string term) { List <string> videos = new List <string>(); List <string> channels = new List <string>(); List <string> playlists = new List <string>(); var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = GlobalVars.YOUTUBE_API_KEY, }); var searchListRequest = youtubeService.Search.List("snippet"); searchListRequest.Q = term; searchListRequest.MaxResults = 1; // Call the search.list method to retrieve results matching the specified query term. var searchListResponse = await searchListRequest.ExecuteAsync(); Stopwatch sw = new Stopwatch(); sw.Start(); // search takes on avg 0.2 - 0.3 seconds while (videos.Count <= 0 && sw.Elapsed.TotalSeconds < GlobalVars.YOUTUBE_MAX_SEARCH_TIME) { searchListRequest.MaxResults++; searchListResponse = await searchListRequest.ExecuteAsync(); foreach (var searchResult in searchListResponse.Items) { switch (searchResult.Id.Kind) { case "youtube#video": videos.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId)); sw.Stop(); //Console.WriteLine("took : " + sw.Elapsed.TotalSeconds); break; //case "youtube#channel": // channels.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.ChannelId)); // break; //case "youtube#playlist": // playlists.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.PlaylistId)); // break; } } } //Console.WriteLine(String.Format("Videos:\n{0}\n", string.Join("\n", videos))); //Console.WriteLine(String.Format("Channels:\n{0}\n", string.Join("\n", channels))); //Console.WriteLine(String.Format("Playlists:\n{0}\n", string.Join("\n", playlists))); if (videos.Count <= 0) { return("Cannot find the video that you requested! (Or youtube api is being too slow and your request has been cancelled)"); } string vidurl = MasterUtils.getWord(videos); //Console.WriteLine("before processing: " + vidurl); string vidID = MasterUtils.reverse(extractVideoID(MasterUtils.reverse(vidurl))); //Console.WriteLine(vids); //Console.WriteLine(vidID); return($"https://www.youtube.com/watch?v={vidID}"); }