SHARE
TWEET

SourceConnectBot source code

a guest Feb 25th, 2017 311 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections.Immutable;
  2. using System.Text.RegularExpressions;
  3. using Discord;
  4.  
  5. namespace SourceConnectLink
  6. {
  7.     // https://discordapp.com/api/oauth2/authorize?client_id=<client id>&scope=bot&permissions=0
  8.     public class CommandListener
  9.     {
  10.         DiscordClient m_Client;
  11.  
  12.         readonly ImmutableArray<Regex> m_Regexes = ImmutableArray.Create(
  13.             new Regex(@"connect\s*(?'ip'\S+)\s*;\s*password\s*(?'pw'\S+);?", RegexOptions.Compiled),
  14.             new Regex(@"password\s*(?'pw'\S+)\s*;\s*connect\s*(?'ip'\S+)\s*;?", RegexOptions.Compiled)
  15.         );
  16.  
  17.         public CommandListener()
  18.         {
  19.             DiscordConfigBuilder configBuilder = new DiscordConfigBuilder();
  20.             configBuilder.AppName = "SourceConnectLink";
  21.  
  22.             m_Client = new DiscordClient(configBuilder);
  23.  
  24.             m_Client.MessageReceived += MessageReceived;
  25.            
  26.             m_Client.Connect("<client secret>", TokenType.Bot);
  27.         }
  28.  
  29.         private void MessageReceived(object sender, MessageEventArgs e)
  30.         {
  31.             if (e.Message.IsAuthor)
  32.                 return;
  33.  
  34.             foreach (Regex r in m_Regexes)
  35.             {
  36.                 Match m = r.Match(e.Message.Text);
  37.                 if (m.Success)
  38.                 {
  39.                     e.Channel.SendMessage(string.Format("steam://connect/{0}/{1}", m.Groups["ip"].Value, m.Groups["pw"].Value));
  40.                     return;
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top