Ejemplo n.º 1
0
 def privateMessage(self, msg):
     # self.fwtAnnounce()
     return
     m = str(msg)
     tmp = RObotLib.decryptPM(m)
     if tmp is not None:
         msgText, sendTo = tmp
         if self.logFilename:
             with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                 lf.write('pm from,{},{},{}\n'.format(
                     sendTo, time.time(), msgText))
         print(
             color(
                 '{}  PM FROM {}: {}'.format(
                     time.strftime("%X", time.localtime()), sendTo,
                     msgText), pmColor))
         msgBody = checkForCommands(msgText)
         if msgBody and sendTo != 'RevelationOrange':
             self.handlePM(msgBody, sendTo)
         elif msgText == 'help':
             self.handlePM('!' + msgText, sendTo)
         elif sendTo == 'RevelationOrange':
             inputs = msgBody.split(' ')
             if inputs[0] == '!say':
                 chatTxt = ' '.join(inputs[1:])
                 resprepl = "<message to='*****@*****.**' from='[email protected]/xiff' type='groupchat' id='dc96ae0e-27ec-40e5-83f2-b4a013d5ec0a' xmlns='jabber:client'><body>{}</body><x xmlns='jabber:x:event'><composing/></x></message>"
                 resp = resprepl.format(chatTxt)
                 print(chatTxt)
                 xmpp.send_raw(resp)
             elif inputs[0] == '!msgs':
                 print(self.pmCmdTimers)
             elif inputs[0] == '!yay':
                 for y in self.yays:
                     print(time.ctime(y))
                 resp = RObotLib.formulateResponse('yay!™', sendTo)
                 if self.logFilename:
                     with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                         lf.write('pm to,{},{},{}\n'.format(
                             sendTo, time.time(), 'yay!™'))
                 print(
                     color('PM TO {}: {}'.format(sendTo, 'yay!™'), pmColor))
                 xmpp.send_raw(resp)
             elif inputs[0] == '!hinders':
                 for x in self.hinderances:
                     print(
                         color('{}: {}'.format(x, self.hinderances[x]),
                               'blue'))
             elif inputs[0] == '!timers':
                 for t in self.publicCooldowns:
                     print(
                         color(
                             "{}: {}".format(
                                 t, time.ctime(self.publicCooldowns[t])),
                             "blue"))
             elif inputs[0] in ['!disconnect', '!dc']:
                 self.logout()
             else:
                 self.handlePM(msgBody, sendTo)
Ejemplo n.º 2
0
 def privateMessage(self, msg):
     m = str(msg)
     tmp = RObotLib.decryptPM(m)
     if tmp is not None:
         msgText, sendTo = tmp
         if self.logFilename:
             with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                 lf.write('pm from,{},{},{}\n'.format(
                     sendTo, time.time(), msgText))
         print(color('PM FROM {}: {}'.format(sendTo, msgText), pmColor))
         msgBody = checkForCommands(msgText)
         if msgBody and sendTo != 'RevelationOrange':
             self.handlePM(msgBody, sendTo)
         elif msgText == 'help':
             self.handlePM('!' + msgText, sendTo)
         elif sendTo == 'RevelationOrange':
             inputs = msgBody.split(' ')
             if inputs[0] == '!say':
                 chatTxt = ' '.join(inputs[1:])
                 resprepl = "<message to='*****@*****.**' from='[email protected]/xiff' type='groupchat' id='dc96ae0e-27ec-40e5-83f2-b4a013d5ec0a' xmlns='jabber:client'><body>{}</body><x xmlns='jabber:x:event'><composing/></x></message>"
                 resp = resprepl.format(chatTxt)
                 print(chatTxt)
                 print(resp)
                 xmpp.send_raw(resp)
             elif inputs[0] == '!msgs':
                 print(self.pmCmdTimers)
             elif inputs[0] == '!yay':
                 for y in self.yays:
                     print(time.ctime(y))
                 resp = RObotLib.formulateResponse('yay!™', sendTo)
                 if self.logFilename:
                     with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                         lf.write('pm to,{},{},{}\n'.format(
                             sendTo, time.time(), 'yay!™'))
                 print(
                     color('PM TO {}: {}'.format(sendTo, 'yay!™'), pmColor))
                 xmpp.send_raw(resp)
             elif inputs[0] == '!hinders':
                 for x in self.hinderances:
                     print(
                         color('{}: {}'.format(x, self.hinderances[x]),
                               'blue'))
             elif inputs[0] == '!ads':
                 for ad in RObotLib.townAdsList:
                     print(color(ad, 'green'))
             else:
                 rMsg = '[construction zone]'
                 resp = RObotLib.formulateResponse(rMsg, sendTo)
                 if self.logFilename:
                     with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                         lf.write('pm to,{},{},{}\n'.format(
                             sendTo, time.time(), rMsg))
                 xmpp.send_raw(resp)
Ejemplo n.º 3
0
 def handlePM(self, msgBody, usr):
     if self.canReply:
         if usr not in self.pmCmdTimers or time.time() - self.pmCmdTimers[usr] > 3.:
             inputs = msgBody.split(' ')
             if usr in self.hinderances and self.hinderances[usr]:
                 if inputs[0][1:] not in ['stopHinder', 'stophinder']:
                     self.hinderances[usr] -= 1
                     inputs[0] = '!' + rng.choice(RObotLib.hinderRNG)
             else:
                 if inputs[0][1:] in ['stopHinder', 'stophinder']:
                     inputs = ['!stophinder', 'err']
             handled = RObotLib.handler(inputs[0][1:], usr, inputs[1:])
             if handled is not None:
                 if inputs[0][1:] == 'hinder':
                     if len(inputs) > 1 and canIntConvert(inputs[1]):
                         nRands = inputs[1]
                     else:
                         nRands = rng.randint(1,5+1)
                     self.hinderances[usr] = nRands
                 elif inputs[0][1:] in ['stopHinder', 'stophinder']:
                     self.hinderances[usr] = 0
                 responses, replyMsgs = handled
                 for i in range(len(responses)):
                     time.sleep(1.2)
                     print(color('PM TO {}: {}'.format(usr, replyMsgs[i]), pmColor))
                     if self.logFilename:
                         with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                             lf.write('pm to,{},{},{}\n'.format(usr, time.time(), replyMsgs[i]))
                     self.send_raw(responses[i])
                 self.pmCmdTimers[usr] = time.time()
             else:
                 print(color('got past checkForCommands, but handler returned None', 'yellow'))
                 print(color(msgBody, 'yellow'), usr)
Ejemplo n.º 4
0
 def shutdownAnnounce(self):
     if time.time() - self.publicCooldowns['shutdown'] >= 7 * 60:
         ttc = RObotLib.getTimeToClosing()
         ttcInM = ttc / 60.
         if ttc <= 3. * 24 * 60 * 60:
             if ttcInM > (72 * 60) - 5 and ttcInM <= 72 * 60:
                 resp = "Dawn of the first day: 72 hours remain"
             elif ttcInM > (60 * 60) - 5 and ttcInM <= 60 * 60:
                 resp = "Night of the first day: 60 hours remain"
             elif ttcInM > (48 * 60) - 5 and ttcInM <= 48 * 60:
                 resp = "Dawn of the second day: 48 hours remain"
             elif ttcInM > (36 * 60) - 5 and ttcInM <= 36 * 60:
                 resp = "Night of the second day: 36 hours remain"
             elif ttcInM > (24 * 60) - 5 and ttcInM <= 24 * 60:
                 resp = "Dawn of the final day: 24 hours remain"
             elif ttcInM > (12 * 60) - 5 and ttcInM <= 12 * 60:
                 resp = "Night of the final day: 12 hours remain"
             elif ttcInM > 0 and ttcInM <= 5:
                 resp = "Five minutes until the moon crashes into... whatever the f**k the name of snp2's kingdom is. Good riddance, King Konrad."
             else:
                 resp = 0
             if resp:
                 r = RObotLib.grpMsgRepl.format(resp)
                 xmpp.send_raw(r)
                 self.publicCooldowns['shutdown'] = time.time()
Ejemplo n.º 5
0
 def muc_online(self, presence):
     # self.fwtAnnounce()
     """
     Process a presence stanza from a chat room. In this case,
     presences from users that have just come online are
     handled by sending a welcome message that includes
     the user's nickname and role in the room.
     Arguments:
         presence -- The received presence stanza. See the
                     documentation for the Presence stanza
                     to see how else it may be used.
     """
     sendMsg = input(">> ")
     while sendMsg != "!!q":
         if sendMsg[:2] == '/w':
             usr = sendMsg.split(' ')[1]
             m = ' '.join(sendMsg.split(' ')[2:])
             resp = RObotLib.formulateResponse(usr, m)
         else:
             resp = grpMsgRepl.format(sendMsg)
         xmpp.send_raw(resp)
         sendMsg = input(">> ")
     self.disconnect()
     return
     '''
Ejemplo n.º 6
0
 def privateMessage(self, msg):
     m = str(msg)
     tmp = RObotLib.decryptPM(m)
     if tmp is not None:
         msgBody, sendTo = tmp
         if self.logFilename:
             with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                 lf.write('pm from,{},{},{}\n'.format(
                     sendTo, time.time(), msgBody))
         print('PM FROM {}: {}'.format(sendTo, msgBody))
         # do stuff with msgBody here, normally
         if sendTo == 'RevelationOrange':
             inputs = msgBody.split(' ')
             if inputs[0] == '!say':
                 chatTxt = ' '.join(inputs[1:])
                 resprepl = "<message to='*****@*****.**' from='[email protected]/xiff' type='groupchat' id='dc96ae0e-27ec-40e5-83f2-b4a013d5ec0a' xmlns='jabber:client'><body>{}</body><x xmlns='jabber:x:event'><composing/></x></message>"
                 resp = resprepl.format(chatTxt)
                 print(chatTxt)
                 print(resp)
                 xmpp.send_raw(resp)
             elif inputs[0] == '!msgs':
                 print(self.pmCmdTimers)
             elif inputs[0] == '!yay':
                 for y in self.yays:
                     print(time.ctime(y))
                 resp = RObotLib.formulateResponse('yay!™', sendTo)
                 if self.logFilename:
                     with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                         lf.write('pm to,{},{},{}\n'.format(
                             sendTo, time.time(), 'yay!™'))
                 xmpp.send_raw(resp)
             else:
                 rMsg = '[construction zone]'
                 resp = RObotLib.formulateResponse(rMsg, sendTo)
                 if self.logFilename:
                     with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                         lf.write('pm to,{},{},{}\n'.format(
                             sendTo, time.time(), rMsg))
                 xmpp.send_raw(resp)
         elif self.canReply:
             self.handlePM(msgBody, sendTo)
Ejemplo n.º 7
0
 def fwtAnnounce(self):
     if time.time() - self.publicCooldowns['fwt'] >= 7 * 60.:
         tier, timeLeft, nxt1, nxt15, nxtSun = RObotLib.getNextFWTD()
         if tier:
             # announce time remaining every 3 hours (use cooldown + range), and a warning half-hour before it ends
             if timeLeft > (
                 (24 * 60) - 5) * 60. and timeLeft <= 24 * 60 * 60.:
                 resp = RObotLib.grpMsgRepl.format(
                     "Happy free world trade day! (trader's guild level {})"
                     .format(tier))
             elif timeLeft > (31 - 5) * 60. and timeLeft <= (31) * 60.:
                 resp = RObotLib.grpMsgRepl.format(
                     "FWT is almost over! {} left.".format(
                         RObotLib.timeTextConverter(timeLeft, False)))
             elif timeLeft and timeLeft <= 60 * 2:
                 resp = RObotLib.grpMsgRepl.format(
                     "FWT is (basically) over! The next one will be happening in {}. Use !fwt for more info."
                     .format(
                         RObotLib.timeTextConverter(
                             min(nxt1, nxt15, nxtSun), False)))
             else:
                 hrs = timeLeft / 3600.
                 hrsApprox = round(hrs)
                 if not hrsApprox % 3 and abs(hrs - hrsApprox) * 60 < 2:
                     resp = RObotLib.grpMsgRepl.format(
                         "FWT active, ~{} hours left.".format(hrsApprox))
                 else:
                     resp = 0
             if resp:
                 xmpp.send_raw(resp)
                 self.publicCooldowns['fwt'] = time.time()
         else:
             nearest = min(nxt1, nxt15, nxtSun)
             if nearest > (31 - 5) * 60. and nearest <= (31) * 60.:
                 # announce ~30 minutes until it starts
                 resp = RObotLib.grpMsgRepl.format(
                     "A free world trade day will be starting in {}!".
                     format(RObotLib.timeTextConverter(nearest, False)))
                 xmpp.send_raw(resp)
                 self.publicCooldowns['fwt'] = time.time()
Ejemplo n.º 8
0
 def muc_message(self, msg):
     if time.time()-self.startTime > 3.2:
         delayTime = 1.0
         grpAndPBcooldown = 15. # minutes
         print(msg['mucnick']+':', msg['body'])
         if self.logFilename:
             with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                 lf.write('{},{},{}\n'.format(msg['mucnick'],time.time(),msg['body']))
         if msg['mucnick'] == 'ChevetteGirl':
             if '<' in msg['body'] or '>' in msg['body']:
                 if 'bunnycuddle' in msg['body'] or 'bunny cuddle' in msg['body']:
                     if self.bunnylogFilename:
                         with codecs.open(self.bunnylogFilename, 'a', 'utf-8') as lf:
                             lf.write('bunnycuddle,{},{}\n'.format(time.time(), msg['body']))
         pbMatch = 'item: poop bucket'
         yayTxt0 = 'yay!™'
         yayTxt1 = 'yay!'
         sheetsTxt = ['!sheets', '!spreadsheets']
         sheetsMsg = "Here's the list of spreadsheets: bit.ly/snp2_sheets"
         if msg['body'][:len(pbMatch)] == pbMatch:
             if time.time() - self.pbTimer >= grpAndPBcooldown * 60.:
                 pbResponse = RObotLib.getKnarfResp()
                 resp = RObotLib.grpMsgRepl.format(pbResponse)
                 time.sleep(delayTime)
                 xmpp.send_raw(resp)
                 self.pbTimer = time.time()
         elif msg['body'][:len(yayTxt1)] == yayTxt1 and msg['mucnick'] not in [x[0] for x in RObotLib.mindyAltsList if x[1] == 'known']:
             if time.time() - self.yayCooldown >= grpAndPBcooldown * 60.:
                 self.yays.append(time.time())
                 if len(self.yays) > 1 and time.time() - self.yays[-2] <= 20.:
                     self.yays = []
                     resp = RObotLib.grpMsgRepl.format(yayTxt0)
                     time.sleep(delayTime)
                     xmpp.send_raw(resp)
                     self.yayCooldown = time.time()
         elif msg['body'] in sheetsTxt:
             if time.time() - self.sheetsCooldown >= grpAndPBcooldown * 60.:
                 resp = RObotLib.grpMsgRepl.format(sheetsMsg)
                 time.sleep(delayTime)
                 xmpp.send_raw(resp)
                 self.sheetsCooldown = time.time()
             else:
                 msgBody = checkForCommands(msg['body'], 'public')
                 if msgBody:
                     self.handlePM(msgBody, msg['mucnick'])
         else:
             msgBody = checkForCommands(msg['body'], 'public')
             if msgBody:
                 self.handlePM(msgBody, msg['mucnick'])
Ejemplo n.º 9
0
 def handlePM(self, msgBody, usr):
     if msgBody[0] == '!':
         if usr not in self.pmCmdTimers or time.time(
         ) - self.pmCmdTimers[usr] > 3.:
             inputs = msgBody.split(' ')
             handled = RObotLib.handler(inputs[0][1:], usr, inputs[1:])
             if handled is not None:
                 responses, replyMsgs = handled
                 for i in range(len(responses)):
                     print('PM TO {}: {}'.format(usr, replyMsgs[i]))
                     if self.logFilename:
                         with codecs.open(self.logFilename, 'a',
                                          'utf-8') as lf:
                             lf.write('pm to,{},{},{}\n'.format(
                                 usr, time.time(), replyMsgs[i]))
                     self.send_raw(responses[i])
                     time.sleep(1.2)
                 self.pmCmdTimers[usr] = time.time()
Ejemplo n.º 10
0
 def muc_message(self, msg):
     delayTime = 1.0
     grpAndPBcooldown = 15.  # minutes
     print(msg['mucnick'] + ':', msg['body'])
     if self.logFilename:
         with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
             lf.write('{},{},{}\n'.format(msg['mucnick'], time.time(),
                                          msg['body']))
     if msg['mucnick'] == 'ChevetteGirl':
         if '<' in msg['body'] or '>' in msg['body']:
             if 'bunnycuddle' in msg['body'] or 'bunny cuddle' in msg[
                     'body']:
                 if self.bunnylogFilename:
                     with codecs.open(self.bunnylogFilename, 'a',
                                      'utf-8') as lf:
                         lf.write('bunnycuddle,{},{}\n'.format(
                             time.time(), msg['body']))
     pbMatch = 'item: poop bucket'
     yayTxt0 = 'yay!™'
     yayTxt1 = 'yay!'
     time.sleep(delayTime)
     if msg['body'][:len(pbMatch)] == pbMatch:
         if time.time() - self.pbTimer >= grpAndPBcooldown * 60.:
             pbResponse = RObotLib.getKnarfResp()
             resp = RObotLib.grpMsgRepl.format(pbResponse)
             xmpp.send_raw(resp)
             self.pbTimer = time.time()
     elif msg['body'][:len(yayTxt1)] == yayTxt1:
         if time.time() - self.yayCooldown >= grpAndPBcooldown * 60.:
             self.yays.append(time.time())
             if len(self.yays) > 1 and time.time() - self.yays[-2] <= 20.:
                 self.yays = []
                 resp = RObotLib.grpMsgRepl.format(yayTxt0)
                 xmpp.send_raw(resp)
                 self.yayCooldown = time.time()
     elif msg['body'][0] == '!' and len(
             msg['body']) > 1 and msg['body'][1] not in [' ', '!']:
         self.handlePM(msg['body'], msg['mucnick'])
     else:
         inputs = msg['body'].split(' ')
         if inputs[0][-1] == ':' and inputs[0][0] not in ["'", '"']:
             chkCmd = inputs[0][:-1]
             if chkCmd in RObotLib.optionDict:
                 self.handlePM('!' + msg['body'], msg['mucnick'])
Ejemplo n.º 11
0
 def muc_message(self, msg):
     if time.time() - self.startTime > 3.2:
         delayTime = 1.0
         grpAndPBcooldown = 15.  # minutes
         print(msg['mucnick'] + ':', msg['body'])
         if self.logFilename:
             with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                 lf.write('{},{},{}\n'.format(msg['mucnick'], time.time(),
                                              msg['body']))
         if msg['mucnick'] == 'ChevetteGirl':
             if '<' in msg['body'] or '>' in msg['body']:
                 if 'bunnycuddle' in msg['body'] or 'bunny cuddle' in msg[
                         'body']:
                     if self.bunnylogFilename:
                         with codecs.open(self.bunnylogFilename, 'a',
                                          'utf-8') as lf:
                             lf.write('bunnycuddle,{},{}\n'.format(
                                 time.time(), msg['body']))
         pbMatch = 'item: poop bucket'
         yayTxt0 = 'yay!™'
         yayTxt1 = 'yay!'
         if msg['body'][:len(pbMatch)] == pbMatch:
             if time.time() - self.pbTimer >= grpAndPBcooldown * 60.:
                 pbResponse = RObotLib.getKnarfResp()
                 resp = RObotLib.grpMsgRepl.format(pbResponse)
                 time.sleep(delayTime)
                 xmpp.send_raw(resp)
                 self.pbTimer = time.time()
         elif msg['body'][:len(yayTxt1)] == yayTxt1:
             if time.time() - self.yayCooldown >= grpAndPBcooldown * 60.:
                 self.yays.append(time.time())
                 if len(self.yays
                        ) > 1 and time.time() - self.yays[-2] <= 20.:
                     self.yays = []
                     resp = RObotLib.grpMsgRepl.format(yayTxt0)
                     time.sleep(delayTime)
                     xmpp.send_raw(resp)
                     self.yayCooldown = time.time()
         else:
             msgBody = checkForCommands(msg['body'])
             if msgBody:
                 self.handlePM(msgBody, msg['mucnick'])
Ejemplo n.º 12
0
 def muc_message(self, msg):
     self.fwtAnnounce()
     self.shutdownAnnounce()
     if time.time() - self.startTime > 3.:
         delayTime = 1.0
         grpAndPBcooldown = 15.  # minutes
         print(time.strftime("%X", time.localtime()), '',
               color(msg['mucnick'] + ':', "purple"), msg['body'])
         if '@RO'.lower() in msg['body'].lower():
             droid.notify(time.strftime("%X", time.localtime()),
                          '{}: {}'.format(msg['mucnick'], msg['body']))
             droid.vibrate(420)
         if self.logFilename:
             with codecs.open(self.logFilename, 'a', 'utf-8') as lf:
                 lf.write('muc,{},{},{}\n'.format(msg['mucnick'],
                                                  time.time(), msg['body']))
         if msg['mucnick'] in ['ChevetteGirl', 'BunHelsing']:
             if '<' in msg['body'] or '>' in msg['body']:
                 if 'bunnycuddle' in msg['body'] or 'bunny cuddle' in msg[
                         'body']:
                     if self.bunnylogFilename:
                         with codecs.open(self.bunnylogFilename, 'a',
                                          'utf-8') as lf:
                             lf.write('bunnycuddle,{},{}\n'.format(
                                 time.time(), msg['body']))
         pbMatch = 'item: poop bucket'
         yayTxt0 = 'yay!™'
         yayTxt1 = 'yay!'
         # sheetsTxt = ['!sheets', '!spreadsheets', '!sheet']
         # sheetsMsg = "Here's the list of spreadsheets: bit.ly/snp2_sheets"
         # gsTxt = ['!gettinstarted', '!gs']
         # gsMsg = "Here's a useful guide for new players: bit.ly/SP2guide"
         # wikiTxt = ['!wiki']
         # refreshTxt = ['!refresh']
         if msg['body'][:len(pbMatch)] == pbMatch:
             if time.time(
             ) - self.publicCooldowns['pb'] >= grpAndPBcooldown * 60.:
                 pbResponse = RObotLib.getKnarfResp()
                 resp = RObotLib.grpMsgRepl.format(pbResponse)
                 time.sleep(delayTime)
                 xmpp.send_raw(resp)
                 self.publicCooldowns['pb'] = time.time()
         # check if problem
         elif msg['body'][:len(yayTxt1)] == yayTxt1:
             if time.time() - self.yayCooldown >= grpAndPBcooldown * 60.:
                 self.yays.append(time.time())
                 if len(self.yays
                        ) > 1 and time.time() - self.yays[-2] <= 20.:
                     self.yays = []
                     resp = RObotLib.grpMsgRepl.format(yayTxt0)
                     time.sleep(delayTime)
                     xmpp.send_raw(resp)
                     self.yayCooldown = time.time()
         else:
             if msg['body'][0] == '!':
                 f = RObotLib.isPub(msg['body'])
                 if f and time.time(
                 ) - self.publicCooldowns[f] >= grpAndPBcooldown * 60.:
                     resp = RObotLib.grpMsgRepl.format(
                         RObotLib.optionDict[f]())
                     time.sleep(delayTime)
                     xmpp.send_raw(resp)
                     self.publicCooldowns[f] = time.time()
                 else:
                     msgBody = checkForCommands(msg['body'], 'public')
                     if msgBody:
                         self.handlePM(msgBody, msg['mucnick'])
             else:
                 msgBody = checkForCommands(msg['body'], 'public')
                 if msgBody:
                     self.handlePM(msgBody, msg['mucnick'])