common.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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:] #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 rights["chan"] == "owner":
  43. if self.channels[event.target].is_owner(event.source.nick):
  44. show = True
  45. if rights["chan"] == "admin":
  46. if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick):
  47. show = True
  48. if rights["chan"] == "oper":
  49. 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):
  50. show = True
  51. if show:
  52. return blue + self.cmdchar + command + reset + ", "
  53. else:
  54. return blue + self.cmdchar + command + reset + ", "
  55. class AdminHelpers():
  56. def get_channelfunctions(self, channel):
  57. channelfunctions = self.db.one("SELECT autojoin, aggressiveness, join_greeting, statistics_commands, games, chat FROM channels WHERE LOWER(name)=LOWER('" + channel + "') AND network='" + self.network + "'")
  58. if channelfunctions[0]:
  59. autojoin = "on"
  60. else:
  61. autojoin = "off"
  62. if channelfunctions[2]:
  63. joingreet = "on"
  64. else:
  65. joingreet = "off"
  66. if channelfunctions[3]:
  67. statscmds = "on"
  68. else:
  69. statscmds = "off"
  70. if channelfunctions[4]:
  71. games = "on"
  72. else:
  73. games = "off"""
  74. if channelfunctions[5]:
  75. chat = "on"
  76. else:
  77. chat = "off"""
  78. 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 + ".")
  79. def is_channelfunction(value):
  80. if value.lower() in ["autojoin", "aggressiveness", "join_greeting", "statistics_commands", "games", "chat"]:
  81. return True
  82. else:
  83. return False
  84. def describe_channelfunction(function):
  85. if function == "autojoin":
  86. message = "Boolean. If the channel will be joined automaticly after connecting."
  87. elif function == "aggressiveness":
  88. message = "How to respond to kick, ban and mode events. Options: " + blue + "passive" + reset + ", " + blue + "defense_only" + reset + "."
  89. elif function == "join_greeting":
  90. message = ""
  91. elif function == "statistics_commands":
  92. message = ""
  93. elif function == "games":
  94. message = ""
  95. elif function == "chat":
  96. message = ""
  97. else:
  98. message = ""
  99. return message
  100. def is_aggressiveness(value):
  101. if value.lower() in ["passive", "defense_only"]:
  102. return True
  103. else:
  104. return False
  105. class GameHelpers():
  106. def roll_dice(amount, type):
  107. rolls = []
  108. for iterations in range(amount):
  109. rolls.append(random.randint(1, type))
  110. return rolls