1
0

common.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import random
  2. from datetime import datetime
  3. from common import queries, userstatus, log
  4. class Protectees():
  5. def update(self, nick, user, host):
  6. if nick in self.protectees: # On record.
  7. if userstatus.atleast_halfop(self, user, self.homechannel) or nick == self.connection.get_nickname(): # Update. Is atleast halfop or bot itself.
  8. self.protectees[nick].update({'ident': nick + "!" + user + "@" + host})
  9. else: # Delete.
  10. del self.protectees[nick]
  11. else: # Append.
  12. if userstatus.atleast_halfop(self, user, self.homechannel) or nick == self.connection.get_nickname(): # Update. Is atleast halfop or bot itself.
  13. self.protectees[nick] = {'ident': nick + "!" + user + "@" + host}
  14. class Replyto():
  15. def name(connection, event):
  16. messages = [
  17. "Hello " + event.source.nick + ".",
  18. "How are you today " + event.source.nick + "?",
  19. "Piss off " + event.source.nick + "!",
  20. event.source.nick + ", what are you botherring me for?",
  21. "Go bother someone else...",
  22. "Is life treating you fair?",
  23. "What's up?",
  24. "Why are you talking to me?",
  25. "I'm not talking to you!",
  26. "What have you been up to?",
  27. "How is life?",
  28. "What do you want from me?",
  29. event.source.nick + ", why are you bothering me?",
  30. event.source.nick + ", when will you stop talking about me?",
  31. event.source.nick + " I hate you!",
  32. "Get bent!",
  33. "Go and cut yourself.",
  34. "Do you think i care about you?",
  35. "Stop nickalerting me " + event.source.nick + ", you wanker!",
  36. ]
  37. actions = [
  38. "hides!",
  39. "dies.",
  40. "runs away.",
  41. "is ignoring that.",
  42. "is not feeling like caring.",
  43. "is away",
  44. "will be ignoring that.",
  45. "is faggaliciouz!! <333",
  46. "likes you! <3",
  47. "looks the other way...",
  48. "does a little dance with " + event.source.nick + ".",
  49. "makes a little love.",
  50. "get's down tonight.",
  51. "thinks SAM Broadcaster sucks raw cocks in hell!",
  52. "is secretly in love with " + event.source.nick + ".",
  53. "tosses " + event.source.nick + "'s salad.",
  54. "tortures " + event.source.nick + " horribly!",
  55. "is smelling like tuna when looking at " + event.source.nick + ".",
  56. "sniffing armpits.. Eew! Smells like " + event.source.nick + ".",
  57. "rapes " + event.source.nick + ".",
  58. "pets " + event.source.nick + ", and sais: Why what a nice little human you are, and such plentifull organs!"
  59. ]
  60. # Reply with a random message or action.
  61. if random.randint(0, 1) == 0:
  62. connection.privmsg(event.target, random.choice(messages))
  63. else:
  64. connection.action(event.target, random.choice(actions))
  65. class Aggressiveness():
  66. def retalliation_reason(self, connection, protectee, behaviour):
  67. if protectee == connection.get_nickname(): # Bot itself.
  68. return "Aggression channel function = " + behaviour + ": Self defense."
  69. else:
  70. return "Aggression channel function = " + behaviour + ": " + protectee + " is atlast halfop in " + self.homechannel + "."
  71. class Lastact():
  72. def update(self, name, type, channel=False, lastact=False, auxiliary=False):
  73. # Create records if not present.
  74. if channel:
  75. queries.create_ifnot_onrecord(self, "channels", channel)
  76. queries.create_ifnot_onrecord(self, "users", name)
  77. # Update record.
  78. self.db.run("UPDATE users SET last_act_type=%s, last_act_datetime=%s, last_act_channel=%s, last_act=%s, last_act_auxiliary=%s WHERE name=%s AND network=%s", (type, str(datetime.now()), channel, lastact, auxiliary, name, self.network))
  79. # Set user back from away, if user is active.
  80. if type not in ["nick", "kick", "part", "quit"]:
  81. self.db.run("UPDATE users SET away=FALSE WHERE name=%s AND network=%s", (name, self.network, ))
  82. class MessageStatistics():
  83. def update(self, event, type):
  84. channel = queries.create_ifnot_onrecord(self, 'channel', event.target)
  85. user = queries.create_ifnot_onrecord(self, 'user', event.source.nick)
  86. if not self.db.one('SELECT id FROM rotbot_' + type + ' WHERE network_id=%(network_id)s AND channel_id=%(channel_id)s AND user_id=%(user_id)s', network_id=self.network.id, channel_id=channel.id ,user_id=user.id): # Not on record.
  87. self.db.run('INSERT INTO rotbot_' + type + ' (network_id, channel_id, user_id, amount) VALUES (%(network_id)s, %(channel_id)s, %(user_id)s, 1)', network_id=self.network.id, channel_id=channel.id ,user_id=user.id) # Create record.
  88. else: # On record.
  89. self.db.run('UPDATE rotbot_' + type + ' SET amount = amount +1 WHERE network_id=%(network_id)s AND channel_id=%(channel_id)s AND user_id=%(user_id)s', network_id=self.network.id, channel_id=channel.id ,user_id=user.id) # Increment record.
  90. class Inform():
  91. def owners(self, connection, message):
  92. log.notice('Message: %s' % (message))
  93. if self.network.home_channel in self.channels:
  94. for owner in self.channels[self.network.home_channel].owners():
  95. connection.privmsg(owner, message)
  96. def notice_owners(self, connection, message):
  97. log.notice('Message: %s' % (message))
  98. if self.network.home_channel in self.channels:
  99. for owner in self.channels[self.network.home_channel].owners():
  100. connection.notice(owner, message)
  101. def operators(self, connection, message):
  102. if self.homechannel in self.channels:
  103. for user in self.channels[self.homechannel].owners():
  104. connection.privmsg(user, message)
  105. for user in self.channels[self.homechannel].admins():
  106. connection.privmsg(user, message)
  107. for user in self.channels[self.homechannel].opers():
  108. connection.privmsg(user, message)
  109. def home_channel(self, connection, message):
  110. connection.privmsg(self.network.home_channel, message)