def channel_user_joined_channel(bot, origin, data): if data[2] not in bot.channel_channels: bot.channel_channels[data[2]] = {} bot.channel_channels[data[2]][data[1]] = [data[1], data[0], datetime.now(), None] l = len(bot.channel_channels[data[2]]) CHANNEL_MAX = bot.config.channel_limit # banlist management nick = normalize_nick(data[0]).lower() """ if bot.store.banlist_re.match(nick): print("Banlist match: " + nick) bot.write_packet(ID.HON_CS_CHANNEL_BAN,data[2],data[0]) else: """ if CHANNEL_MAX == 0: return if l > CHANNEL_MAX: l -= CHANNEL_MAX for i in sorted(bot.channel_channels[data[2]].values(), key=lambda x: x[2]): if l <= 0: break nick = normalize_nick(i[1]) if ( i[0] not in bot.clan_roster and nick not in bot.config.whitelist and i[1].split("]")[0] not in ["[GM", "[S2"] ): bot.write_packet(ID.HON_CS_CHANNEL_KICK, data[2], i[0]) sleep(0.5) bot.write_packet( ID.HON_CS_WHISPER, i[1], "Sorry, too many people in channel, we need some place for active members" ) l -= 1 sleep(0.5)
def channel_user_joined_channel(bot,origin,data): if data[0] not in bot.channel_channels: bot.channel_channels[data[0]] = {} bot.channel_channels[data[0]][data[2]] = [data[2],data[1],datetime.now(),None] l = len(bot.channel_channels[data[0]]) CHANNEL_MAX = bot.config.channel_limit #banlist management nick = normalize_nick(data[1]).lower() if data[2] in bot.clan_roster: if bot.config.promote_clan: bot.write_packet( ID.HON_CS_CHANNEL_PROMOTE, data[0], data[2] ) if not 'upgrades' in bot.clan_roster[data[2]]: bot.clan_roster[data[2]]['upgrades'] = user_upgrades(data, 1) if CHANNEL_MAX == 0: return if l > CHANNEL_MAX: l -= CHANNEL_MAX for i in sorted(bot.channel_channels[data[0]].values(), key=lambda x:x[2]): if l <= 0:break nick = normalize_nick(i[1]) if i[0] not in bot.clan_roster and nick not in bot.config.whitelist and i[1].split(']')[0] not in ['[GM','[S2']: bot.write_packet(ID.HON_CS_CHANNEL_KICK,data[2],i[0]) sleep(0.5) bot.write_packet(ID.HON_CS_WHISPER,i[1],'Sorry, too many people in channel, we need some place for active members') l -= 1 sleep(0.5)
def channel_user_joined_channel(bot,origin,data): if data[2] not in bot.channel_channels: bot.channel_channels[data[2]] = {} bot.channel_channels[data[2]][data[1]] = [data[1],data[0],datetime.now(),None] l = len(bot.channel_channels[data[2]]) CHANNEL_MAX = bot.config.channel_limit #banlist management nick = normalize_nick(data[0]).lower() if data[1] in bot.clan_roster: if bot.config.promote_clan: bot.write_packet( ID.HON_CS_CHANNEL_PROMOTE, data[2], data[1] ) if not 'upgrades' in bot.clan_roster[data[1]]: bot.clan_roster[data[1]]['upgrades'] = user_upgrades(data, 1) if CHANNEL_MAX == 0: return if l > CHANNEL_MAX: l -= CHANNEL_MAX for i in sorted(bot.channel_channels[data[2]].values(), key=lambda x:x[2]): if l <= 0:break nick = normalize_nick(i[1]) if i[0] not in bot.clan_roster and nick not in bot.config.whitelist and i[1].split(']')[0] not in ['[GM','[S2']: bot.write_packet(ID.HON_CS_CHANNEL_KICK,data[2],i[0]) sleep(0.5) bot.write_packet(ID.HON_CS_WHISPER,i[1],'Sorry, too many people in channel, we need some place for active members') l -= 1 sleep(0.5)
def joined_channel(bot,packet_id,data): bot.chan2id[data[0]] = data[1] bot.id2chan[data[1]] = data[0] for m in data[-1]: m[0] = normalize_nick(m[0]) bot.nick2id[m[0]] = m[1] bot.id2nick[m[1]] = m[0]
def user_joined_channel(bot,origin,data): nick = normalize_nick(data[0]) bot.id2clan[data[1]] = GetClanTag(data[0]) bot.nick2clan[nick] = bot.id2clan[data[1]] bot.nick2id[nick] = data[1] bot.id2nick[data[1]] = nick bot.user_status[data[1]] = data[3]
def user_joined_channel(bot, origin, data): nick = normalize_nick(data[1]) bot.id2clan[data[2]] = GetClanTag(data[1]) bot.nick2clan[nick] = bot.id2clan[data[2]] bot.nick2id[nick] = data[2] bot.id2nick[data[2]] = nick bot.user_status[data[2]] = data[3]
def joined_channel(bot,origin,data): bot.chan2id[data[0].lower()] = data[1] bot.id2chan[data[1]] = data[0] for m in data[-1]: m[0] = normalize_nick(m[0]) bot.nick2id[m[0]] = m[1] bot.id2nick[m[1]] = m[0]
def __new__(cls, text, origin, data, match): s = unicode.__new__(cls, text) s.origin = origin #s.sender = origin.sender #s.nick = origin.nick s.data = data s.match = match s.group = match.group s.groups = match.groups if isinstance(origin[1],unicode): origin[1] = normalize_nick(origin[1]) s.nick = origin[1] try: s.account_id = self.nick2id[s.nick.lower()] except: s.account_id = -1 elif isinstance(origin[1],int): s.account_id = origin[1] try: s.nick = self.id2nick[origin[1]] except: s.nick = '' else: s.nick = None s.account_id = None s.owner = s.nick.lower() == self.config.owner.lower() s.admin = s.owner or s.nick.lower() in self.config.admins s.admin = s.admin or hasattr(self.config,'clan_admin') and self.config.clan_admin and s.account_id in self.clan_roster if not s.admin and hasattr(self.config,'officer_admin') and \ self.config.officer_admin and s.account_id is not None and\ s.account_id in self.clan_roster and\ self.clan_roster[s.account_id]['rank'] != 'Member': s.admin = True return s
def __new__(cls, text, origin, data, match): s = unicode.__new__(cls, text) s.origin = origin #s.sender = origin.sender #s.nick = origin.nick s.data = data s.match = match s.group = match.group s.groups = match.groups if isinstance(origin[1], unicode): origin[1] = normalize_nick(origin[1]) s.nick = origin[1] try: s.account_id = self.nick2id[s.nick.lower()] except: s.account_id = -1 elif isinstance(origin[1], int): s.account_id = origin[1] try: s.nick = self.id2nick[origin[1]] except: s.nick = '' else: s.nick = None s.account_id = None s.owner = s.nick == self.config.owner s.admin = s.owner or s.nick.lower() in self.config.admins if not s.admin and hasattr(self.config,'officer_admin') and \ self.config.officer_admin and s.account_id is not None and\ s.account_id in self.clan_roster and\ self.clan_roster[s.account_id]['rank'] != 'Member': s.admin = True return s
def channel_joined_channel(bot,origin,data): bot.channel_channels[data[1]] = dict([[m[1],[m[1],m[0],datetime.now(),None]] for m in data[-1]]) #banlist management for m in data[-1]: nick = normalize_nick(m[0]).lower() if bot.store.banlist_re.match(nick): bot.write_packet(ID.HON_CS_CHANNEL_BAN,data[1],nick)
def auth(self): auth_data = masterserver.auth(self.config.nick, self.config.password) if 'ip' not in auth_data or 'auth_hash' not in auth_data: print("Login Failure") return False # print json.dumps(auth_data, indent=4) self.ip = auth_data['ip'] self.cookie = auth_data['cookie'] self.account_id = int(auth_data['account_id']) self.auth_hash = auth_data['auth_hash'] self.got_len = False self.nick = auth_data['nickname'] self.id2nick[self.account_id] = self.nick self.nick2id[self.nick] = self.account_id if "clan_member_info" in auth_data: self.clan_info = auth_data["clan_member_info"] else: self.clan_info = {} if "clan_roster" in auth_data and "error" not in auth_data[ "clan_roster"]: self.clan_roster = auth_data["clan_roster"] else: self.clan_roster = {} if "buddy_list" in auth_data: buddy_list = auth_data["buddy_list"] else: buddy_list = {} self.buddy_list = {} for id in self.clan_roster: if self.clan_roster[id]['nickname']: nick = normalize_nick(self.clan_roster[id]['nickname']).lower() self.id2nick[id] = nick self.nick2id[nick] = id for buddies in buddy_list.values(): for buddy in buddies.values(): try: id = int(buddy['buddy_id']) self.buddy_list[id] = buddy nick = normalize_nick(buddy['nickname']) self.id2nick[id] = nick self.nick2id[nick] = id except: pass return auth_data
def auth(self): auth_data = masterserver.auth(self.config.nick,self.config.password) if 'ip' not in auth_data or 'auth_hash' not in auth_data: print("Login Failure") return False # print json.dumps(auth_data, indent=4) self.ip = auth_data['ip'] self.cookie = auth_data['cookie'] self.account_id = int(auth_data['account_id']) self.auth_hash = auth_data['auth_hash'] self.got_len = False self.nick = auth_data['nickname'] self.id2nick[self.account_id] = self.nick self.nick2id[self.nick] = self.account_id if "clan_member_info" in auth_data: self.clan_info = auth_data["clan_member_info"] else: self.clan_info = {} if "clan_roster" in auth_data and "error" not in auth_data["clan_roster"]: self.clan_roster = auth_data["clan_roster"] else: self.clan_roster = {} if "buddy_list" in auth_data: buddy_list = auth_data["buddy_list"] else: buddy_list = {} self.buddy_list = {} for id in self.clan_roster: if self.clan_roster[id]['nickname']: nick = normalize_nick(self.clan_roster[id]['nickname']).lower() self.id2nick[id] = nick self.nick2id[nick] = id for buddies in buddy_list.values(): for buddy in buddies.values(): try: id = int(buddy['buddy_id']) self.buddy_list[id] = buddy nick = normalize_nick(buddy['nickname']) self.id2nick[id] = nick self.nick2id[nick] = id except:pass return auth_data
def joined_channel(bot, origin, data): print("Joined " + data[0]) bot.chan2id[data[0].lower()] = data[1] bot.id2chan[data[1]] = data[0].lower() for m in data[-1]: bot.id2clan[m[1]] = GetClanTag(m[0]) m[0] = normalize_nick(m[0]) bot.nick2clan[m[0]] = bot.id2clan[m[1]] bot.nick2id[m[0]] = m[1] bot.id2nick[m[1]] = m[0] bot.user_status[m[1]] = m[2]
def joined_channel(bot,origin,data): print("Joined " + data[0]) bot.chan2id[data[0].lower()] = data[1] bot.id2chan[data[1]] = data[0].lower() for m in data[-1]: bot.id2clan[m[1]] = GetClanTag(m[0]) m[0] = normalize_nick(m[0]) bot.nick2clan[m[0]] = bot.id2clan[m[1]] bot.nick2id[m[0]] = m[1] bot.id2nick[m[1]] = m[0] bot.user_status[m[1]] = m[2]
def run(self): auth_data = masterserver.auth(self.config.nick, self.config.password) print('got auth data') #print auth_data,self.config.nick,self.config.password self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.ip = auth_data['ip'] self.cookie = auth_data['cookie'] self.account_id = int(auth_data['account_id']) self.auth_hash = auth_data['auth_hash'] self.got_len = False self.nick = auth_data['nickname'] if "clan_member_info" in auth_data: self.clan_info = auth_data["clan_member_info"] else: self.clan_info = {} if "clan_roster" in auth_data and "error" not in auth_data[ "clan_roster"]: self.clan_roster = auth_data["clan_roster"] else: self.clan_roster = {} if "buddy_list" in auth_data: buddy_list = auth_data["buddy_list"] else: buddy_list = {} self.buddy_list = {} for id in self.clan_roster: nick = normalize_nick(self.clan_roster[id]['nickname']) self.id2nick[id] = nick self.nick2id[nick] = id for buddies in buddy_list.values(): for buddy in buddies.values(): id = int(buddy['buddy_id']) nick = normalize_nick(buddy['nickname']) self.id2nick[id] = nick self.nick2id[nick] = id self.buddy_list[id] = buddy self.connect((auth_data['chat_url'], packets.ID.HON_CHAT_PORT)) asyncore.loop()
def run(self): auth_data = masterserver.auth(self.config.nick,self.config.password) print ('got auth data') #print auth_data,self.config.nick,self.config.password self.create_socket( socket.AF_INET, socket.SOCK_STREAM ) self.ip = auth_data['ip'] self.cookie = auth_data['cookie'] self.account_id = int(auth_data['account_id']) self.auth_hash = auth_data['auth_hash'] self.got_len = False self.nick = auth_data['nickname'] if "clan_member_info" in auth_data: self.clan_info = auth_data["clan_member_info"] else: self.clan_info = {} if "clan_roster" in auth_data and "error" not in auth_data["clan_roster"]: self.clan_roster = auth_data["clan_roster"] else: self.clan_roster = {} if "buddy_list" in auth_data: buddy_list = auth_data["buddy_list"] else: buddy_list = {} self.buddy_list = {} for id in self.clan_roster: nick = normalize_nick(self.clan_roster[id]['nickname']) self.id2nick[id] = nick self.nick2id[nick] = id for buddies in buddy_list.values(): for buddy in buddies.values(): id = int(buddy['buddy_id']) nick = normalize_nick(buddy['nickname']) self.id2nick[id] = nick self.nick2id[nick] = id self.buddy_list[id] = buddy self.connect( ( auth_data['chat_url'], packets.ID.HON_CHAT_PORT ) ) asyncore.loop()
def dispatch(self,data): self.connection_timeout = time.time() origin,data = packets.parse_packet(data) packet_id = origin[0] source = normalize_nick(origin[1]).lower() if origin[1] != None and isinstance(origin[1], unicode) else None owner = self.config.owner.lower() if source == owner and isinstance(data, unicode) and len(data) > 0 and data[0] not in ['!', '.']: self.post_to_twitch(data) else: for priority in ('high', 'medium', 'low'): items = self.commands[priority].items() for regexp, funcs in items: for func in funcs: if packet_id not in func.event: continue if regexp is None: if func.thread: targs = (func, list(origin), self,list(origin), data) t = threading.Thread(target=self.call, args=targs) t.start() else: self.call(func, list(origin), self, list(origin),data) elif isinstance(data,unicode): text = data match = regexp.match(text) if match: input = self.input(list(origin), text, data, match) if input.nick.lower() in self.config.ignore: continue phenny = self.wrapped(list(origin), input, text, match) t = time.time() if input.admin or input.nick not in self.cooldowns or\ (input.nick in self.cooldowns \ and \ t - self.cooldowns[input.nick]\ >= self.config.cooldown): self.cooldowns[input.nick] = t if func.thread: targs = (func, list(origin), phenny, input) t = threading.Thread(target=self.call, args=targs) t.start() else: self.call(func, list(origin), phenny, input)
def __new__(cls, text, origin, data, match): s = unicode.__new__(cls, text) s.origin = origin #s.sender = origin.sender #s.nick = origin.nick s.data = data s.match = match s.group = match.group s.groups = match.groups if isinstance(origin[1], unicode): origin[1] = normalize_nick(origin[1]) s.nick = origin[1] s.account_id = self.nick2id[s.nick] elif isinstance(origin[1], int): s.account_id = origin[1] s.nick = self.id2nick[origin[1]] else: s.nick = None s.account_id = None s.admin = origin[1] in self.config.admins s.owner = origin[1] == self.config.owner return s
def __new__(cls, text, origin, data, match): s = unicode.__new__(cls, text) s.origin = origin #s.sender = origin.sender #s.nick = origin.nick s.data = data s.match = match s.group = match.group s.groups = match.groups if isinstance(origin[1],unicode): origin[1] = normalize_nick(origin[1]) s.nick = origin[1] s.account_id = self.nick2id[s.nick] elif isinstance(origin[1],int): s.account_id = origin[1] s.nick = self.id2nick[origin[1]] else: s.nick = None s.account_id = None s.admin = origin[1] in self.config.admins s.owner = origin[1] == self.config.owner return s
def channel_user_joined_channel_smurfs(bot,origin,data): nick = normalize_nick(data[0]).lower() silence_smurfs(bot,data[2],nick)
def name_change(bot, origin, data): nick = normalize_nick(data[1]) bot.nick2id[nick] = data[0] bot.id2nick[data[0]] = nick
def ply_join_ban(bot, origin, data): nick = normalize_nick(data[1]) if bot.banlist.IsBanlisted(nick): for chan in bot.channel_channels.keys(): bot.write_packet(ID.HON_CS_CHANNEL_BAN, chan, nick)
def ply_join_ban(bot, origin, data): nick = normalize_nick(data[0]) if bot.banlist.IsBanlisted(nick): for chan in bot.channel_channels.keys(): bot.write_packet(ID.HON_CS_CHANNEL_BAN, chan, nick)
def channel_user_joined_channel_smurfs(bot,origin,data): nick = normalize_nick(data[1]).lower() silence_smurfs(bot,data[0],nick)
def name_change(bot,origin,data): nick = normalize_nick(data[1]) bot.nick2id[nick] = data[0] bot.id2nick[data[0]] = nick
def user_joined_channel(bot,packet_id,data): nick = normalize_nick(data[0]) bot.nick2id[nick] = data[1] bot.id2nick[data[1]] = nick
def logwhisper(bot, origin, data): nick = normalize_nick(origin[1]) log_message(bot, nick, WHISP_PSEUDO_CHANNEL, data)
def bot_join_ban(bot, origin, data): for m in data[-1]: nick = normalize_nick(m[0]).lower() if bot.banlist.IsBanlisted(nick): for chan in bot.channel_channels.keys(): bot.write_packet(ID.HON_CS_CHANNEL_BAN, chan, nick)
def user_joined_channel(bot,origin,data): nick = normalize_nick(data[0]).lower() bot.nick2id[nick] = data[1] bot.id2nick[data[1]] = nick