Esempio n. 1
0
 public void Process(object sender, IRCEventArgs e)
 {
     if (e.IsChannelMessage && Triggers.TryGetValue(e.Channel, out var triggers))
     {
         var urls = e.ContentTokens.Where(s => s.StartsWith("http:", StringComparison.InvariantCultureIgnoreCase) || s.StartsWith("https:", StringComparison.InvariantCultureIgnoreCase));
         if (urls.Any() && (triggers.Contains(string.Empty) || triggers.Contains(e.ContentTokens.First())))
         {
             foreach (var s in urls)
             {
                 if (UrlBlacklist.Any(b => s.Contains(b)))
                 {
                     continue;
                 }
                 Task t = new Task(async() => {
                     string title = GetUrlTitle(s);
                     if (!string.IsNullOrWhiteSpace(title))
                     {
                         await(sender as IRCClient).SendToChannelAsync(e.Channel, title);
                     }
                 });
                 t.Start();
             }
         }
     }
 }
Esempio n. 2
0
        public async void Process(object sender, IRCEventArgs args)
        {
            if (args.IsChannelMessage && Triggers.TryGetValue(args.Channel, out var triggers) && triggers.Any(t => args.Tokens[3] == t))
            {
                var client = sender as IRCClient;
                //assume trigger is token[3]
                var contentTokens = args.Tokens.Skip(4);
                if (!contentTokens.Any())
                {
                    await client.SendToChannelAsync(args.Channel, $"{args.Sender}: There are no choices to choose from!");

                    return;
                }
                var choices = string.Join(" ", contentTokens).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (!choices.Any())
                {
                    await client.SendToChannelAsync(args.Channel, $"{args.Sender}: There are no choices to choose from!");

                    return;
                }
                var result = choices.OrderBy(c => GetRandomByte()).FirstOrDefault();
                await client.SendToChannelAsync(args.Channel, $"{args.Sender}: {result.Trim()}");
            }
        }