Skip to content

Instantly share code, notes, and snippets.

@SinZ163
Created March 5, 2019 12:35
Show Gist options
  • Select an option

  • Save SinZ163/e3d4b7f82d3fbce9767aa33e21e2f835 to your computer and use it in GitHub Desktop.

Select an option

Save SinZ163/e3d4b7f82d3fbce9767aa33e21e2f835 to your computer and use it in GitHub Desktop.
import re
import traceback
ID = "discord"
permission = 3
cmdList = ("pycalc", "convert", "utc", "workshop", "match", "prize", "valvetime", "api")
def execute(self, name, params, channel, userdata, rank):
pass
def __initialize__(self, Startup):
if self.events["chat"].doesExist("Discord_privmsg"):
self.events["chat"].removeEvent("Discord_privmsg")
self.events["chat"].addEvent("Discord_privmsg", onPrivmsg)
def onPrivmsg(self, channels, userdata, message, currChannel):
#print("A")
try:
if userdata["name"] == "D|":
#print("B")
#print(message)
#print("<.(?P<rank>\d\d)(?P<name>.+?).> (?P<message>.+?)$")
match = re.search("<.(?P<rank>\d\d)(?P<name>.+?).> (?P<message>.+?)$", message)
#print("C")
#print("D")
output = match.groupdict()
chatParams = output["message"].rstrip().split(" ")
#print("E")
#print(str(len(chatParams[0])))
#print(chatParams[0][0:2])
if chatParams[0][0] == self.cmdprefix and chatParams[0][1:] in self.commands:
#print("F")
if chatParams[0][1:] not in cmdList:
self.sendMessage(currChannel, "Unsupported command for irc bridge. Can only use "+", ".join(cmdList))
return
#print("G")
try:
direct_msg_support = self.commands[chatParams[0][1:]][0].privmsgEnabled
except AttributeError:
direct_msg_support = False
#print("H")
if direct_msg_support:
#print("I")
self.commands[chatParams[0][1:]][0].execute(self, "[Discord]_"+output["name"], chatParams[1:], currChannel, ("discord", "discord"), "", chan = True)
#print("J")
else:
#print("K")
self.commands[chatParams[0][1:]][0].execute(self, "[Discord]_"+output["name"], chatParams[1:], currChannel, ("discord", "discord"), "")
#print("L")
elif len(chatParams[0]) == 2 and chatParams[0][0:2] == "??":
#print("We have a faq?")
#must be 2
self.commands["faq"][0].execute(self, "[Discord]_"+output["name"], [""] + chatParams[1:], currChannel, ("discord", "discord"), "")
except:
print(traceback.format_exc())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment