Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Immutable;
- using System.Text.RegularExpressions;
- using Discord;
- namespace SourceConnectLink
- {
- // https://discordapp.com/api/oauth2/authorize?client_id=<client id>&scope=bot&permissions=0
- public class CommandListener
- {
- DiscordClient m_Client;
- readonly ImmutableArray<Regex> m_Regexes = ImmutableArray.Create(
- new Regex(@"connect\s*(?'ip'\S+)\s*;\s*password\s*(?'pw'\S+);?", RegexOptions.Compiled),
- new Regex(@"password\s*(?'pw'\S+)\s*;\s*connect\s*(?'ip'\S+)\s*;?", RegexOptions.Compiled)
- );
- public CommandListener()
- {
- DiscordConfigBuilder configBuilder = new DiscordConfigBuilder();
- configBuilder.AppName = "SourceConnectLink";
- m_Client = new DiscordClient(configBuilder);
- m_Client.MessageReceived += MessageReceived;
- m_Client.Connect("<client secret>", TokenType.Bot);
- }
- private void MessageReceived(object sender, MessageEventArgs e)
- {
- if (e.Message.IsAuthor)
- return;
- foreach (Regex r in m_Regexes)
- {
- Match m = r.Match(e.Message.Text);
- if (m.Success)
- {
- e.Channel.SendMessage(string.Format("steam://connect/{0}/{1}", m.Groups["ip"].Value, m.Groups["pw"].Value));
- return;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement