Created
January 21, 2016 17:53
-
-
Save zodman/83b8b4e95fee86892591 to your computer and use it in GitHub Desktop.
pyiab plugin for authenticate with mattermost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pyaib plugin for auth with matterircd | |
from pyaib.plugins import * | |
import time | |
@plugin_class('mattermost') | |
class Mattermost(object): | |
""" track channels and stuff """ | |
def __init__(self, irc_c, config): | |
self.config = config | |
self.password = config.password | |
@keyword('join') | |
def join(self, irc_c, msg, trigger, args, kargs): | |
if len(args) > 0: | |
irc_c.JOIN(args) | |
@keyword('part') | |
def part(self, irc_c, msg, trigger, args, kargs): | |
if len(args) > 0: | |
irc_c.PART(args, message='%s asked me to leave.' % msg.nick) | |
@keyword('invite') | |
def invite(self, irc_c, msg, trigger, args, kargs): | |
if len(args) > 0 and args[0].startswith('#'): | |
irc_c.RAW('INVITE %s :%s' % (msg.nick, args[0])) | |
@observe('IRC_MSG_INVITE') | |
def follow_invites(self, irc_c, msg): | |
if msg.target == irc_c.botnick: # Sanity | |
irc_c.JOIN(msg.message) | |
irc_c.PRIVMSG(msg.message, '%s: I have arrived' % msg.nick) | |
@observe('IRC_RAW_MSG', 'IRC_RAW_SEND') | |
def debug(self, irc_c, msg): | |
print("[%s] %r" % (time.strftime('%H:%M:%S'), msg)) | |
@observes('IRC_ONCONNECT') | |
def AUTO_IDENTIFY(self, irc_c): | |
if irc_c.config.debug: | |
return | |
self.identify(irc_c) | |
#Spawn off a watcher that makes sure we have the nick we want | |
irc_c.timers.clear('mattermost', self.watcher) | |
irc_c.timers.set('mattermost', self.watcher, every=90) | |
def watcher(self, irc_c, timertext): | |
if irc_c.botnick != irc_c.config.irc.nick: | |
self.identify(irc_c) | |
def identify(self, irc_c): | |
#Identify | |
print("Identifying with mattermost") | |
irc_c.PRIVMSG('mattermost', 'LOGIN %s' % self.password) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment