def fmvoice(self, irc, msg, args, option): """Takes no arguments Podela igraca u dve grupe, voice/devoice.""" voices_empty = [] channel = msg.args[0] voices = irc.state.channels[channel].voices voices_length = len(voices) users = irc.state.channels[channel].users users_length = len(users) half_users_length = users_length / 2 list_of_users = list(users) if '--first' in msg.args[1]: for i in xrange(half_users_length + 2): nick = random.choice(list_of_users) if nick == "eRepublikBot" or nick == "DonVitoCorleone": continue if nick not in voices: irc.queueMsg(ircmsgs.voice(channel, nick)) elif '--devoice' in msg.args[1]: for i in users: irc.queueMsg(ircmsgs.devoice(channel, i)) else: for i in users: if i not in voices: irc.queueMsg(ircmsgs.voice(channel, i)) elif i == 'eRepublikBot' or i == "DonVitoCorleone" or i == "x-bot": continue else: irc.queueMsg(ircmsgs.devoice(channel, i))
def doJoin(self, irc, msg): """give voice to users that join and meet requirements.""" if msg.args[0] != '#bitcoin-otc' or irc.network != 'freenode': return gpgauth = self._checkGPGAuth(irc, msg.prefix) if gpgauth is None: if not self.registryValue('msgOnJoin'): return try: if msg.nick not in irc.state.channels['#bitcoin-otc-foyer'].users: irc.queueMsg(ircmsgs.privmsg(msg.nick, "Join #bitcoin-otc-foyer and see channel topic for instructions on getting voice on #bitcoin-otc.")) return except KeyError: return info = self._getGPGInfo(irc, gpgauth['nick']) if info is not None: regtimestamp = info[4] else: # this should not happen return trust_nanotube = self._gettrust(irc, 'nanotube', gpgauth['nick']) trust_keefe = self._gettrust(irc, 'keefe', gpgauth['nick']) mintrust = min(trust_nanotube[0][0] + trust_nanotube[1][0], trust_keefe[0][0] + trust_keefe[1][0]) if mintrust >= self.registryValue('ratingThreshold') and \ time.time() - regtimestamp > self.registryValue('accountAgeThreshold'): irc.queueMsg(ircmsgs.voice('#bitcoin-otc', msg.nick))
def doJoin(self, irc, msg): """give voice to users that join and meet requirements.""" if msg.args[0] != self.registryValue('targetChannel') or irc.network != 'freenode': return if msg.nick == irc.nick: # ignore our own join msgs. return gpgauth = self._checkGPGAuth(irc, msg.prefix) if gpgauth is None: try: if (not world.testing) and self.registryValue('msgOnJoinVoice') != "" and msg.nick not in irc.state.channels['#bitcoin-otc-foyer'].users: irc.queueMsg(ircmsgs.privmsg(msg.nick, self.registryValue('msgOnJoinVoice'))) except KeyError: pass if (not world.testing) and self.registryValue('msgOnJoinIdent') != "": irc.queueMsg(ircmsgs.privmsg(msg.nick, self.registryValue('msgOnJoinIdent'))) return info = self._getGPGInfo(irc, gpgauth['nick']) if info is not None: regtimestamp = info[4] else: # this should not happen return trust_nanotube = self._gettrust(irc, 'nanotube', gpgauth['nick']) trust_keefe = self._gettrust(irc, 'keefe', gpgauth['nick']) mintrust = min(trust_nanotube[0][0] + trust_nanotube[1][0], trust_keefe[0][0] + trust_keefe[1][0]) if mintrust >= self.registryValue('ratingThreshold') and \ time.time() - regtimestamp > self.registryValue('accountAgeThreshold'): irc.queueMsg(ircmsgs.voice('#bitcoin-otc', msg.nick))
def confirm(self, irc, msg, args, code): """<code> Confirm a user registration, you must be in a channel the bot is in.""" if not self.nickInAnyChannel(irc, msg.nick): irc.reply("To confirm your account, you must be in a channel that I am in. Try joining #ircpuzzles.") return if msg.nick not in self._cache: irc.reply("You are not identified to NickServ. Please identify and try again.") return account = self._cache[msg.nick].lower() logger.info("Nick %s (account %s) requesting confirmation" % (msg.nick,account)) code_found = False users = list(session.query(User).filter(User.account == account)) if len(users) < 1: irc.reply("No user was found with your NickServ account. Please try registering again.") return for user in users: if user.confirmed == True: irc.reply("You are already confirmed!") return if user.confirmation_code == code: user.confirmed = True session.query(User).filter(User.account == account).filter(User.id != user.id).delete() session.commit() irc.reply("Thank you, your account is now confirmed!") if self._game: if msg.nick in irc.state.channels[self._game.lobby.name].users: irc.queueMsg(ircmsgs.voice(self._game.lobby.name,msg.nick)) return irc.reply("Incorrect confirmation code.")
def letmein(self, irc, msg, args): """takes no arguments Gives you voice on #bitcoin-otc if you qualify. Also invites you if needed. """ gpgauth = self._checkGPGAuth(irc, msg.prefix) if gpgauth is None: irc.error("You must authenticate via GPG to use this command.") return info = self._getGPGInfo(irc, gpgauth['nick']) if info is not None: regtimestamp = info[4] else: # this should not happen irc.error("No info on your user in the database.") return trust_nanotube = self._gettrust(irc, 'nanotube', gpgauth['nick']) trust_keefe = self._gettrust(irc, 'keefe', gpgauth['nick']) mintrust = min(trust_nanotube[0][0] + trust_nanotube[1][0], trust_keefe[0][0] + trust_keefe[1][0]) if mintrust >= self.registryValue('ratingThreshold') and \ time.time() - regtimestamp > self.registryValue('accountAgeThreshold'): if msg.nick not in irc.state.channels[self.registryValue('targetChannel')].users and \ self.registryValue('invite'): irc.queueMsg(ircmsgs.invite(msg.nick, self.registryValue('targetChannel'))) irc.reply("You have been invited to %s. Type '/j %s' to enter the channel." % (self.registryValue('targetChannel'), self.registryValue('targetChannel'),)) if msg.nick in irc.state.channels[self.registryValue('targetChannel')].users: irc.queueMsg(ircmsgs.voice(self.registryValue('targetChannel'), msg.nick)) irc.noReply() else: irc.error("Insufficient account age or rating. Required minimum account age is %s days, and required minimum trust is %s. Yours are %s days and %s, respectively." % (self.registryValue('accountAgeThreshold')/60/60/24, self.registryValue('ratingThreshold'),(time.time() - regtimestamp)/60/60/24, mintrust))
def doJoin(self, irc, msg): """give voice to users that join and meet requirements.""" if msg.args[0] != '#bitcoin-otc' or irc.network != 'freenode': return gpgauth = self._checkGPGAuth(irc, msg.prefix) if gpgauth is None: if not self.registryValue('msgOnJoin'): return try: if msg.nick not in irc.state.channels[ '#bitcoin-otc-foyer'].users: irc.queueMsg( ircmsgs.privmsg( msg.nick, "Join #bitcoin-otc-foyer and see channel topic for instructions on getting voice on #bitcoin-otc." )) return except KeyError: return info = self._getGPGInfo(irc, gpgauth['nick']) if info is not None: regtimestamp = info[4] else: # this should not happen return trust_nanotube = self._gettrust(irc, 'nanotube', gpgauth['nick']) trust_keefe = self._gettrust(irc, 'keefe', gpgauth['nick']) mintrust = min(trust_nanotube[0][0] + trust_nanotube[1][0], trust_keefe[0][0] + trust_keefe[1][0]) if mintrust >= self.registryValue('ratingThreshold') and \ time.time() - regtimestamp > self.registryValue('accountAgeThreshold'): irc.queueMsg(ircmsgs.voice('#bitcoin-otc', msg.nick))
def letmein(self, irc, msg, args): """takes no arguments Gives you voice on #bitcoin-otc if you qualify. """ gpgauth = self._checkGPGAuth(irc, msg.prefix) if gpgauth is None: irc.error("You must authenticate via GPG to get voice.") return info = self._getGPGInfo(irc, gpgauth['nick']) if info is not None: regtimestamp = info[4] else: # this should not happen irc.error("No info on your user in the database.") return trust_nanotube = self._gettrust(irc, 'nanotube', gpgauth['nick']) trust_keefe = self._gettrust(irc, 'keefe', gpgauth['nick']) mintrust = min(trust_nanotube[0][0] + trust_nanotube[1][0], trust_keefe[0][0] + trust_keefe[1][0]) if mintrust >= self.registryValue('ratingThreshold') and \ time.time() - regtimestamp > self.registryValue('accountAgeThreshold'): irc.queueMsg(ircmsgs.voice('#bitcoin-otc', msg.nick)) irc.noReply() else: irc.error( "Insufficient account age or rating. Required minimum account age is %s days, and required minimum trust is %s. Yours are %s days and %s, respectively." % (self.registryValue('accountAgeThreshold') / 60 / 60 / 24, self.registryValue('ratingThreshold'), (time.time() - regtimestamp) / 60 / 60 / 24, mintrust))
def doMode(self, irc, msg): channel = msg.channel chanOp = ircdb.makeChannelCapability(channel, 'op') chanVoice = ircdb.makeChannelCapability(channel, 'voice') chanHalfOp = ircdb.makeChannelCapability(channel, 'halfop') if not ircdb.checkCapability(msg.prefix, chanOp): irc.sendMsg(ircmsgs.deop(channel, msg.nick)) for (mode, value) in ircutils.separateModes(msg.args[1:]): if not value: continue if ircutils.strEqual(value, msg.nick): # We allow someone to mode themselves to oblivion. continue if irc.isNick(value): hostmask = irc.state.nickToHostmask(value) if mode == '+o': if not self.isOp(irc, channel, hostmask): irc.queueMsg(ircmsgs.deop(channel, value)) elif mode == '+h': if not ircdb.checkCapability(hostmask, chanHalfOp): irc.queueMsg(ircmsgs.dehalfop(channel, value)) elif mode == '+v': if not ircdb.checkCapability(hostmask, chanVoice): irc.queueMsg(ircmsgs.devoice(channel, value)) elif mode == '-o': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.op(channel, value)) elif mode == '-h': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.halfop(channel, value)) elif mode == '-v': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.voice(channel, value)) else: assert ircutils.isUserHostmask(value)
def letmein(self, irc, msg, args): """takes no arguments Gives you voice on #bitcoin-otc if you qualify. """ gpgauth = self._checkGPGAuth(irc, msg.prefix) if gpgauth is None: irc.error("You must authenticate via GPG to get voice.") return info = self._getGPGInfo(irc, gpgauth['nick']) if info is not None: regtimestamp = info[4] else: # this should not happen irc.error("No info on your user in the database.") return trust_nanotube = self._gettrust(irc, 'nanotube', gpgauth['nick']) trust_keefe = self._gettrust(irc, 'keefe', gpgauth['nick']) mintrust = min(trust_nanotube[0][0] + trust_nanotube[1][0], trust_keefe[0][0] + trust_keefe[1][0]) if mintrust >= self.registryValue('ratingThreshold') and \ time.time() - regtimestamp > self.registryValue('accountAgeThreshold'): irc.queueMsg(ircmsgs.voice('#bitcoin-otc', msg.nick)) irc.noReply() else: irc.error("Insufficient account age or rating. Required minimum account age is %s days, and required minimum trust is %s. Yours are %s days and %s, respectively." % (self.registryValue('accountAgeThreshold')/60/60/24, self.registryValue('ratingThreshold'),(time.time() - regtimestamp)/60/60/24, mintrust))
def doMode(self, irc, msg): channel = msg.args[0] chanOp = ircdb.makeChannelCapability(channel, 'op') chanVoice = ircdb.makeChannelCapability(channel, 'voice') chanHalfOp = ircdb.makeChannelCapability(channel, 'halfop') if not ircdb.checkCapability(msg.prefix, chanOp): irc.sendMsg(ircmsgs.deop(channel, msg.nick)) for (mode, value) in ircutils.separateModes(msg.args[1:]): if not value: continue if ircutils.strEqual(value, msg.nick): # We allow someone to mode themselves to oblivion. continue if irc.isNick(value): hostmask = irc.state.nickToHostmask(value) if mode == '+o': if not self.isOp(irc, channel, hostmask): irc.queueMsg(ircmsgs.deop(channel, value)) elif mode == '+h': if not ircdb.checkCapability(hostmask, chanHalfOp): irc.queueMsg(ircmsgs.dehalfop(channel, value)) elif mode == '+v': if not ircdb.checkCapability(hostmask, chanVoice): irc.queueMsg(ircmsgs.devoice(channel, value)) elif mode == '-o': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.op(channel, value)) elif mode == '-h': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.halfop(channel, value)) elif mode == '-v': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.voice(channel, value)) else: assert ircutils.isUserHostmask(value)
def voice(): if msg.nick not in irc.state.channels[channel].users: self.log.warn('%s is no longer in %s, cannot voice' % (msg.nick, channel)) return self.log.info('Removing muzzle from %s in %s' % (msg.nick, channel)) irc.queueMsg(ircmsgs.voice(channel, msg.nick))
def doJoin(self, irc, msg): """ Announces players joining if supyworld.testing: """ player = self._add_players_from_channel(new_player_nick=msg.nick) if player is not None: """ Voice recognized users """ irc.queueMsg(ircmsgs.voice(GAME_CHANNEL, msg.nick))
def handleUserJoin(self, irc, msg): if len(msg.args) > 1: channel, account, realname = msg.args else: channel, account, realname = (msg.args[0],'*','*') gameChannels = self.getChannels() if msg.nick == irc.nick: return if account in owners: logger.debug('user %s is owner, not handling join' % msg.nick) return if not self._game: return game = self._game if channel == game.lobby.name: logger.debug('nick %s (account %s) joined lobby %s' % (msg.nick,account,channel)) if account == '*': irc.reply('Welcome %s! You must be identified to compete. All game channels are set +r.' % msg.nick) # Notify user as a friendly warning else: user = session.query(User).filter(User.account == account.lower()).filter(User.confirmed == True).count() if user: irc.queueMsg(ircmsgs.voice(channel, msg.nick)) elif channel in gameChannels: if account == '*': irc.queueMsg(remove(channel,msg.nick,'You must be identified with NickServ to play ircpuzzles.')) # Should never be reached as channels are +r return user = list(session.query(User).filter(User.account == account.lower()).filter(User.confirmed == True)) if len(user) < 1: irc.queueMsg(remove(channel,msg.nick,'You must be registered with the bot to compete. Please register at http://ircpuzzles.org.')) return u = user[0] joins_cur = list(session.query(Join).filter(Join.channel == channel).filter(Join.user == u)) if len(joins_cur) > 0: return # User has already joined this channel channel_obj = game.get_channel(channel) prev = channel_obj.prev if not prev: logger.debug('user %s joined channel %s (first in track)' % (u,channel)) join = Join(user=u,channel=channel) logger.debug('adding join obj for %s to %s' % (u,channel)) session.add(join) session.commit() self.alert(irc, channel, u) return # Channel is first in track, user is good joins = list(session.query(Join).filter(Join.channel == prev.name).filter(Join.user == u)) if len(joins) < 1: irc.queueMsg(remove(channel,msg.nick,'You must complete tracks in order.')) return join = Join(user=u,channel=channel) logger.debug('adding join obj for %s to %s' % (u,channel)) session.add(join) session.commit() self.alert(irc, channel, u)
def voicecommander(self, irc, msg, args): channel = msg.args[0] chan = irc.state.channels[channel] if msg.nick not in chan.users: self.log.info("User %s (%s) tried to use VoiceCommander without joined any channel.", \ msg.nick, irc.state.nickToHostmask(msg.nick)) return if not chan.isVoice(msg.nick) and not chan.isOp(msg.nick): irc.error("You are missing capability: op or voice") return if (len(args) == 0): irc.reply("Usage: @voicecommander [topic] [voice] argument(s)") return cmd = args[0] self.randomdelay() # Mitigate against excess flooding # Ability to change topic if cmd.lower() == "topic": if len(args) < 2: irc.error("Ehh.. forgot something? Like.... topic?") return topic = ' '.join(args[1:]) irc.queueMsg(ircmsgs.topic(channel, topic)) # Ability to delegate voices elif cmd.lower() == "voice": if len(args) < 2: irc.error("Need nick as an argument, you fool") return for whom in args[1:]: #whom = args[1] if whom not in chan.users: irc.reply("Nick '%s' not in channel %s" % (whom, channel)) return #if irc.nick in irc.state.channels[channel].voices: # irc.reply("Nick '%s' already voiced" % (whom)) # return irc.queueMsg(ircmsgs.voice(channel, whom))
def __call__(self, irc, msg): # only re-read the file every 60 seconds if self.lastCalled + 60 < int(time.time()): self.readMACs() self.lastCalled = int(time.time()) chan = msg.args[0]; # FIXME: change channel! if(ircutils.isChannel(chan) and chan == "#stratum0" and chan in irc.state.channels.keys()): self.log.info("voices: %s" % repr(irc.state.channels[chan].voices)) self.log.info("present: %s" % repr(self.presentEntities)) self.log.info("devoice %s" % repr(irc.state.channels[chan].voices - self.presentEntities)) self.log.info("voice: %s\n" % repr(self.presentEntities - irc.state.channels[chan].voices)) for nick in (irc.state.channels[chan].voices - self.presentEntities): irc.queueMsg(ircmsgs.devoice(chan, nick)) for nick in (self.presentEntities - irc.state.channels[chan].voices): irc.queueMsg(ircmsgs.voice(chan, nick))
def testHandlesModes(self): st = irclib.IrcState() st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix)) self.failIf('bar' in st.channels['#foo'].ops) st.addMsg(self.irc, ircmsgs.op('#foo', 'bar')) self.failUnless('bar' in st.channels['#foo'].ops) st.addMsg(self.irc, ircmsgs.deop('#foo', 'bar')) self.failIf('bar' in st.channels['#foo'].ops) self.failIf('bar' in st.channels['#foo'].voices) st.addMsg(self.irc, ircmsgs.voice('#foo', 'bar')) self.failUnless('bar' in st.channels['#foo'].voices) st.addMsg(self.irc, ircmsgs.devoice('#foo', 'bar')) self.failIf('bar' in st.channels['#foo'].voices) self.failIf('bar' in st.channels['#foo'].halfops) st.addMsg(self.irc, ircmsgs.halfop('#foo', 'bar')) self.failUnless('bar' in st.channels['#foo'].halfops) st.addMsg(self.irc, ircmsgs.dehalfop('#foo', 'bar')) self.failIf('bar' in st.channels['#foo'].halfops)
def sjoin(self, irc, msg, args, user, character_class): """ Choose a class: Zen Master, Hacker, or Troll """ user_id = user.id char_name = msg.nick channel = GAME_CHANNEL dungeon = self.SpiffyWorld.get_dungeon_by_channel(channel) if dungeon is not None: valid_registration = self._is_valid_char_class(character_class) if valid_registration: unit_type_id = self._get_unit_type_id_by_name( character_class) if unit_type_id is not None: log.info("SpiffyRPG: %s -> register '%s' the '%s' with class id %s " % (msg.nick, char_name, character_class, unit_type_id)) self.SpiffyWorld.unit_model.register_new_player( user_id, char_name, unit_type_id) dungeon.announcer.new_player(char_name, character_class) if not supyworld.testing: irc.queueMsg(ircmsgs.voice(GAME_CHANNEL, msg.nick)) else: log.error( "SpiffyRPG: error determining class id from '%s'" % character_class) else: classes = self._get_unit_type_list() irc.reply( "Please choose one of the following classes: %s" % classes, notice=True) else: irc.error("No dungeon!")
def _doAutoVoice(self, irc, nick): if nick not in irc.state.channels[self.registryValue('monitorChannel')].ops: irc.queueMsg(ircmsgs.voice(self.registryValue('monitorChannel'), nick))