common.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import random
  2. bold = "\x02"
  3. italic = "\x1D"
  4. underline = "\x1F"
  5. reverse = "\x16" # swap background and foreground colors ("reverse video")
  6. reset = "\x0F"
  7. blue = "\x0302"
  8. green = "\x0303"
  9. red = "\x0304"
  10. grey = "\x0314"
  11. class CommandHelpers():
  12. def disect_command(self, event):
  13. trigger = event.arguments[0]
  14. command = trigger[1:].lower() #Command without prefix.
  15. # Determine command type.
  16. if trigger.startswith(self.cmdchar):
  17. cmdtype = "cmd"
  18. elif trigger.startswith(self.helpchar):
  19. cmdtype = "help"
  20. else:
  21. cmdtype = False
  22. # Determine where to reply to.
  23. if event.type == "pubmsg":
  24. replyto = event.target
  25. elif event.type == "privmsg":
  26. replyto = event.source.nick
  27. else:
  28. replyto = False
  29. return(cmdtype, trigger, command, replyto)
  30. def ccc(self, command, rights=False, event=False): # Commandlist colour coding and channel rights filter.
  31. if rights:
  32. show = False
  33. if rights["homechan"] == "owner":
  34. if self.channels[self.homechannel].is_owner(event.source.nick):
  35. show = True
  36. if rights["homechan"] == "admin":
  37. if self.channels[self.homechannel].is_owner(event.source.nick) or self.channels[self.homechannel].is_admin(event.source.nick):
  38. show = True
  39. if rights["homechan"] == "oper":
  40. if self.channels[self.homechannel].is_owner(event.source.nick) or self.channels[self.homechannel].is_admin(event.source.nick) or self.channels[self.homechannel].is_oper(event.source.nick):
  41. show = True
  42. if not event.target == self.connection.get_nickname(): # Channel message.
  43. if rights["chan"] == "owner":
  44. if self.channels[event.target].is_owner(event.source.nick):
  45. show = True
  46. if rights["chan"] == "admin":
  47. if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick):
  48. show = True
  49. if rights["chan"] == "oper":
  50. if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick) or self.channels[event.target].is_oper(event.source.nick):
  51. show = True
  52. if show:
  53. return blue + self.cmdchar + command + reset + ", "
  54. else:
  55. return blue + self.cmdchar + command + reset + ", "
  56. class AdminHelpers():
  57. def get_channelfunctions(self, channel):
  58. channelfunctions = self.db.one("SELECT autojoin, aggressiveness, join_greeting, statistics_commands, games, chat FROM channels WHERE LOWER(name)=LOWER('" + channel + "') AND network='" + self.network + "'")
  59. if channelfunctions[0]:
  60. autojoin = "on"
  61. else:
  62. autojoin = "off"
  63. if channelfunctions[2]:
  64. joingreet = "on"
  65. else:
  66. joingreet = "off"
  67. if channelfunctions[3]:
  68. statscmds = "on"
  69. else:
  70. statscmds = "off"
  71. if channelfunctions[4]:
  72. games = "on"
  73. else:
  74. games = "off"""
  75. if channelfunctions[5]:
  76. chat = "on"
  77. else:
  78. chat = "off"""
  79. return ("autojoin " + green + autojoin + reset + ", aggressiveness " + green + channelfunctions[1] + reset + ", join_greeting " + green + joingreet + reset + ", statistics_commands " + green + statscmds + reset + ", games " + green + games + reset + ", chat " + green + chat + reset + ".")
  80. def is_channelfunction(value):
  81. if value.lower() in ["autojoin", "aggressiveness", "join_greeting", "statistics_commands", "games", "chat"]:
  82. return True
  83. else:
  84. return False
  85. def describe_channelfunction(function):
  86. if function == "autojoin":
  87. message = "Join the channel automaticly after connecting."
  88. elif function == "aggressiveness":
  89. message = "How to respond to kick, ban and mode events. Options: " + blue + "passive" + reset + ", " + blue + "defense_only" + reset + ", " + blue + "equal_retalliation" + reset + ", " + blue + "battlebot" + reset + "."
  90. elif function == "join_greeting":
  91. message = "Greet users joining the channel on the first few joins, and later on large amounts."
  92. elif function == "statistics_commands":
  93. message = "Enable use of statistics commands."
  94. elif function == "games":
  95. message = "Enable use of game commands."
  96. elif function == "chat":
  97. message = "Respond to and initiate chat."
  98. else:
  99. message = "Sorry, this function has no description yet."
  100. return message
  101. def is_aggressiveness(value):
  102. if value.lower() in ["passive", "defense_only", "equal_retalliation", "battlebot"]:
  103. return True
  104. else:
  105. return False
  106. class GameHelpers():
  107. def roll_dice(amount, type):
  108. rolls = []
  109. for iterations in range(amount):
  110. rolls.append(random.randint(1, type))
  111. return rolls