public.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. from common import userstatus, queries, font
  2. from commands.common import CommandHelpers as CH
  3. def do_command(self, connection, event):
  4. cmdtype, trigger, command, replyto = CH.disect_command(self, event)
  5. # Do nothing if it's not a type of command.
  6. if not cmdtype:
  7. return
  8. # Do nothing if there is no command.
  9. if not command:
  10. return
  11. # The first word of the command sting with arguments, is just the command without arguments.
  12. try:
  13. one = command.split()[0]
  14. except:
  15. return
  16. # The actual commands:
  17. # if command == "test":
  18. # if cmdtype == "help": #Display help text.
  19. # if len(command.split()) != 1:
  20. # return
  21. # connection.privmsg(replyto, "Strictly for testing purposes only!")
  22. # elif cmdtype == "cmd":
  23. # connection.privmsg(replyto, str(self.channels[self.homechannel].owners()))
  24. # connection.privmsg(event.source.nick, self.channels[event.target].users())
  25. if command == "cmd" or command == "cmds" or command == "commands":
  26. if cmdtype == "help": #Display help text.
  27. if len(command.split()) != 1:
  28. return
  29. connection.privmsg(replyto, "Displays a list of commands.")
  30. elif cmdtype == "cmd":
  31. if not event.target == connection.get_nickname() and not self.db.one("SELECT join_greeting FROM channels WHERE name='" + event.target + "' AND network='" + self.network + "'"):
  32. connection.privmsg(replyto, grey + "Public: " + CH.ccc(self, "cmd") + CH.ccc(self, "help"))# + CH.ccc(self, "away")[:-2] + ".")
  33. else:
  34. connection.privmsg(replyto, grey + "Public: " + CH.ccc(self, "cmd") + CH.ccc(self, "help"))# + CH.ccc(self, "away") + CH.ccc(self, "stopgreet")[:-2] + ".")
  35. elif command == "help":
  36. if cmdtype == "help": #Display help text.
  37. if len(command.split()) != 1:
  38. return
  39. connection.privmsg(replyto, "Explains how to get help on any specific command and hints the user to the commandlist.")
  40. elif cmdtype == "cmd":
  41. connection.privmsg(replyto, "Replace the " + font.italic + "! " + reset + "prefix of any comand with " + font.italic + self.helpchar + " " + reset + "for help with a specific command. Request the command list with: " + blue + "!cmd")
  42. connection.privmsg(replyto, grey + "Example: " + reset + blue + self.helpchar + "help")
  43. # elif one == "stopgreet":
  44. # if cmdtype == "help": #Display help text.
  45. # if len(command.split()) != 1:
  46. # return
  47. # connection.privmsg(replyto, "Stops the bot from greeting you or a specific user. Channel, user and option to resume optional.")
  48. # connection.privmsg(replyto, grey + "Usage: " + blue + "!stopgreet " + reset + font.italic + "resume " + font.red + "channel user")
  49. # elif cmdtype == "cmd":
  50. #
  51. # # Check for resume variation of command.
  52. # resume = False
  53. # try:
  54. # if command.split()[1] == "resume":
  55. # resume = True
  56. # command = command.split(' ', 1)[1] # Remove the resume argument. Which makes the following logic easier.
  57. # except:
  58. # pass
  59. #
  60. # if len(command.split()) == 1: # No arguments.
  61. # if event.target == connection.get_nickname(): # PM.
  62. # connection.privmsg(replyto, "Specify at least a channel. For help type " + blue + self.helpchar + "stopgreet" + reset + ".")
  63. # return
  64. # user = event.source.nick
  65. # channel = event.target
  66. #
  67. # if len(command.split()) == 2: # One argument.
  68. # if command.split()[1] not in self.channels: # Argument is not a channel the bot inhabits.
  69. # if event.target == connection.get_nickname(): # PM.
  70. # connection.action(replyto, "does not inhabit " + font.red + command.split()[1] + reset + ".")
  71. # return
  72. # # Channel message
  73. # if not userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not userstatus.atleast_halfop(self, event.source.nick, event.target): # Insufficient rights.
  74. # connection.privmsg(replyto, "Denied. You need to have at least halfop status in " + font.red + self.homechannel + reset + " or " + font.red + event.target + reset + ".")
  75. # return
  76. # # Stopgreet for x user in current channel
  77. # user = command.split()[1]
  78. # channel = event.target
  79. # else: # Bot inhabit channel.
  80. # user = event.source.nick
  81. # channel = command.split()[1]
  82. # if len(command.split()) == 3: # Two arguments.
  83. # if command.split()[1] not in self.channels: # Bot does not inhabit channel.
  84. # connection.action(replyto, "does not inhabit " + font.red + command.split()[1] + reset + ".")
  85. # return
  86. # if not userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not userstatus.atleast_halfop(self, event.source.nick, command.split()[1]): # Insufficient rights.
  87. # connection.privmsg(replyto, "Denied. You need to have at least halfop status in " + font.red + self.homechannel + reset + " or " + font.red + command.split()[1] + reset + ".")
  88. # return
  89. # user = command.split()[2]
  90. # channel = command.split()[1]
  91. # if len(command.split()) > 3: # Too many arguments.
  92. # connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "stopgreet" + reset + ".")
  93. # return
  94. #
  95. # # Check for database record.
  96. # result = self.db.one("SELECT id, stopgreet FROM joins WHERE LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "' AND LOWER(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "'")
  97. # if not result: # No record in database.
  98. # connection.action(replyto, "has not yet had the pleasure of greeting " + font.red + user + reset + " in " + font.red + channel + reset + ".")
  99. # return
  100. #
  101. # if resume:
  102. # stopgreet = False
  103. # message = "has already every intention to greet "
  104. # else:
  105. # stopgreet = True
  106. # message = "has already stopped greeting "
  107. # if result[1] == stopgreet:
  108. # connection.action(replyto, message + font.red + user + reset + " in " + font.red + channel + reset + ".")
  109. # return
  110. # print(str(stopgreet) + str(user) + str(channel))
  111. # try:
  112. # self.db.run("UPDATE joins SET stopgreet='" + str(stopgreet) + "' WHERE LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "' AND lower(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "'")
  113. # except:
  114. # connection.privmsg(replyto, "Failed to update database.")
  115. #
  116. # elif one == "away":
  117. # if cmdtype == "help": #Display help text.
  118. # if len(command.split()) != 1:
  119. # return
  120. # connection.privmsg(replyto, "Sets you away, optionally with reason. This affects the !seen command and the game.")
  121. # connection.privmsg(replyto, grey + "Usage: " + blue + "!away " + reset + font.italic + "reason")
  122. #
  123. # elif cmdtype == "cmd":
  124. # queries.create_ifnot_onrecord(self, "users", event.source.nick)
  125. # if len(trigger.split()) == 1:
  126. # self.db.run("UPDATE users SET away=TRUE, away_reason=NULL WHERE name='" + event.source.nick + "' AND network='" + self.network + "'")
  127. # else:
  128. # self.db.run("UPDATE users SET away=TRUE, away_reason=%s WHERE name='" + event.source.nick + "' AND network='" + self.network + "'", (trigger.split(maxsplit=1)[1], ))