Example #1
0
		public ChannelMessage OnChannelMessage(ChannelMessage c, PassableMutableObject v) {
			if (!c.SplitArgs[1].CaseEquals(Def.Keys.First()))
				return null;

			c.Target = c.Nickname;
			string query = c.SplitArgs.Count < 4 ? c.SplitArgs[2] : $"{c.SplitArgs[2]}%20{c.SplitArgs[3]}".Replace(" ", "%20"),
				response =
					HttpGet("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=" +
							query);

			if (c.SplitArgs.Count < 3) {
				c.Message = "Insufficient parameters. Type 'eve help lookup' to view correct usage.";
				return c;
			}

			JToken pages = JObject.Parse(response)["query"]["pages"].Values().First();
			if (string.IsNullOrEmpty((string) pages["extract"])) {
				c.Message = "Query failed to return results. Perhaps try a different term?";
				return c;
			}

			c.MultiMessage = new List<string> {
				$"\x02{(string) pages["title"]}\x0F — "
			};
			c.MultiMessage.AddRange(SplitStr(Regex.Replace((string) pages["extract"], @"\n\n?|\n", " "), 440));

			return c;
		}
Example #2
0
		public ChannelMessage OnChannelMessage(ChannelMessage c, PassableMutableObject v) {
			Regex youtubeRegex =
				new Regex(@"(?i)http(?:s?)://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(?<ID>[\w\-]+)(&(amp;)?[\w\?=‌​]*)?",
					RegexOptions.Compiled);

			if (!youtubeRegex.IsMatch(c.Args)) return null;

			string get =
				HttpGet(
					$"https://www.googleapis.com/youtube/v3/videos?part=snippet&id={youtubeRegex.Match(c.Args).Groups["ID"]}&key=AIzaSyDnKtEZGuv3PgmePOSe6xBvoXKbrEMVxx8");

			JToken video = JObject.Parse(get)["items"][0]["snippet"];
			string channel = (string) video["channelTitle"];
			string title = (string) video["title"];
			string description = video["description"].ToString().Split('\n')[0];
			string[] descArray = description.Split(' ');

			if (description.Length > 200) {
				description = "";

				for (int i = 0; description.Length < 200; i++)
					description += $" {descArray[i]}";

				description += "....";
			}

			c.Message = $"{title} (by {channel}) — {description}";
			return c;
		}
Example #3
0
		public ChannelMessage OnChannelMessage(ChannelMessage c, PassableMutableObject v) {
			if (!c.SplitArgs[1].CaseEquals(Def.Keys.First()))
				return null;

			if (c.SplitArgs.Count < 3) {
				c.Message = "Insufficient parameters. Type 'eve help lookup' to view correct usage.";
				return c;
			}

			JObject entry =
				JObject.Parse(
					HttpGet(
						$"https://api.pearson.com:443/v2/dictionaries/lasde/entries?headword={c.SplitArgs[2]}&limit=1&part_of_speech={(c.SplitArgs.Count > 3 ? c.SplitArgs[3] : null)}"));
			var _out = new Dictionary<string, string>();

			if ((int) entry.SelectToken("count") < 1) {
				c.Message = "Query returned no results.";
				return c;
			}

			_out.Add("word", (string) entry.SelectToken("results[0].headword"));
			_out.Add("pos", (string) entry.SelectToken("results[0].part_of_speech"));
			_out.Add("def", (string) entry.SelectToken("results[0].senses[0].definition[0]"));
			_out.Add("ex", (string) entry.SelectToken("results[0].senses[0].examples[0].text"));

			string sOut = $"{_out["word"]} [{_out["pos"]}] — {_out["def"]}";
			if (string.IsNullOrEmpty(_out["ex"]))
				sOut += $" (ex. {_out["ex"]})";

			c.Message = sOut;
			return c;
		}