Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ch
- import random
- import sys
- import re
- import time
- Trusted = ['Vici0usX']
- dancemoves = [
- "(>^.^)>",
- "(v^.^)v",
- "v(^.^v)",
- "<(^.^<)"
- ]
- bios = [
- "where is the bios?",
- "where do i get bios",
- "where do I get the bios",
- "Bios files?",
- ]
- #################################################
- # Manager
- #################################################
- class MyManager(ch.RoomManager):
- """
- Extends RoomManager to override and implement its unimplemented functions
- as if RoomManager were an abstract class, as well as add new functions.
- """
- #####
- # Overridden functions from RoomManager
- #####
- def onInit(self):
- """
- Called on init.
- """
- pass
- def onConnect(self, room):
- """
- Called when connected to the room.
- @type room: Room
- @param room: room where the event occured
- """
- output = "Successfully connected to " + room.getName() + "!" + \
- "\t(" + self._getLongTimeStamp() + ")"
- print(output)
- def onReconnect(self, room):
- """
- Called when reconnected to the room.
- @type room: Room
- @param room: room where the event occured
- """
- output = "Reconnected to " + room.getName() + "."
- print(output)
- def onConnectFail(self, room):
- """
- Called when the connection failed.
- @type room: Room
- @param room: room where the event occured
- """
- self.reconnect()
- def onDisconnect(self, room):
- """
- Called when the client gets disconnected.
- @type room: Room
- @param room: room where the event occured
- """
- output = "Disconnected from " + room.getName() + "." + \
- "\t(" + self._getLongTimeStamp() + ")"
- print(output)
- def onLoginFail(self, room):
- """
- Called on login failure, disconnects after.
- @type room: Room
- @param room: room where the event occured
- """
- pass
- def onFloodBan(self, room):
- """
- Called when either flood banned or flagged.
- @type room: Room
- @param room: room where the event occured
- """
- output = "Flagged. Please wait 15 minutes."
- print(output)
- def onFloodBanRepeat(self, room):
- """
- Called when trying to send something when floodbanned.
- @type room: Room
- @param room: room where the event occured
- """
- output = "Can't post: still flagged."
- print(output)
- def onFloodWarning(self, room):
- """
- Called when an overflow warning gets received.
- @type room: Room
- @param room: room where the event occured
- """
- print("\a")
- room.setSilent(True)
- output = "This is a flood warning for " + room.getName() + "."
- print(output)
- def onMessageDelete(self, room, user, message):
- """
- Called when a message gets deleted.
- @type room: Room
- @param room: room where the event occured
- @type user: User
- @param user: owner of deleted message
- @type message: Message
- @param message: message that got deleted
- """
- output = "Post deleted.\n\t" + \
- "Author:\t" + user.name + "\n\t" + \
- "IP:\t\t" + message.ip
- print(output)
- def onModChange(self, room):
- """
- Called when the moderator list changes.
- @type room: Room
- @param room: room where the event occured
- """
- output = "The mod list has been updated."
- print(output)
- def onModAdd(self, room, user):
- """
- Called when a moderator gets added.
- @type room: Room
- @param room: room where the event occured
- """
- output = "Someone was promoted to chat mod.\n\t" + \
- "User:\t" + user.name + "\n\t" + \
- "Time:\t" + self._getShortTimeStamp()
- print(output)
- def onModRemove(self, room, user):
- """
- Called when a moderator gets removed.
- @type room: Room
- @param room: room where the event occured
- """
- output = "Someone was demoted from chat mod.\n\t" + \
- "User:\t" + user.name + "\n\t" + \
- "Time\t" + self._getShortTimeStamp()
- print(output)
- def onMessage(self, room, user, message):
- """
- Called when a message gets received.
- @type room: Room
- @param room: room where the event occured
- @type user: User
- @param user: owner of message
- @type message: Message
- @param message: received message
- """
- # Log the message
- output = "Message posted to room.\n\t" + \
- "Author:\t" + user.name + "\n\t" + \
- "IP:\t\t" + message.ip + "\n\t" + \
- "Body:\t" + message.getBody() + "\n\t" + \
- "Time:\t" + self._getShortTimeStamp()
- print(output)
- # Obey authorized commands, if any
- # Insert how to check for and execute commands here. Below is an
- # example.
- if(message.getBody() == "Where is the bot?"):
- room.message("Here I am!")
- if(message.getBody() == "Where do I get bios?"):
- room.message("BIOS files are located at: http://www.roms4droid.com/bios.php")
- if(message.getBody() == "Where is the bios"):
- room.message("BIOS files are located at: http://www.roms4droid.com/bios.php")
- if(message.getBody() == "Where can I get bios?"):
- room.message("BIOS files are located at: http://www.roms4droid.com/bios.php")
- if not message.body.lower().find("bios")
- and not message.body.lower().find("where"):
- room.message("BIOS files are located at: http://www.roms4droid.com/bios.php")
- if(message.getBody() == "I need bios files"):
- room.message("BIOS files are located at: http://www.roms4droid.com/bios.php")
- if(message.getBody() == "hello"):
- room.message("Hello there! Welcome to Roms4Droid. For a list of commands, type !help")
- if(message.getBody() == "hi"):
- room.message("Hello there! Welcome to Roms4Droid. For a list of commands, type !help")
- if(message.getBody() == "help"):
- room.message("Need Help? Visit our online how-to guides: http://www.roms4droid.com/guides.php or post a topic in the forum: http://www.roms4droid.com/forum/index.php")
- if(message.getBody() == "Bye"):
- room.message("Good bye! Thanks for coming :)")
- if room.getLevel(self.user) > 0:
- print(user.name, message.ip, message.body)
- else:
- print(user.name, message.body)
- if self.user == user: return
- if message.body[0] == "!":
- data = message.body[1:].split(" ", 1)
- if len(data) > 1:
- cmd, args = data[0], data[1]
- else:
- cmd, args = data[0], ""
- if cmd == "delay":
- self.setTimeout(int(args), room.message, ":D")
- elif cmd == "randomuser":
- room.message(random.choice(room.usernames))
- elif cmd == "ival":
- self.setInterval(int(args), room.message, ":D")
- elif cmd == "mylvl":
- room.message("Your mod level: %i" %(room.getLevel(user)))
- elif cmd == "mods":
- room.message(", ".join(room.modnames + [room.ownername]))
- elif cmd == "help":
- room.message("Commands: !bios, !roms, !guides, !mods, !mylvl")
- elif cmd == "bios":
- room.message("BIOS Files are located at: http://www.roms4droid.com/bios.php")
- elif cmd == "roms":
- room.message("ROM Files are located at: http://www.roms4droid.com/roms.php")
- #elif cmd == "leave"):
- #room.message("As you wish, my lord.")
- #room.disconnect()
- #break
- elif cmd == "guides":
- room.message("Guides are located at: http://www.roms4droid.com/guides.php")
- elif cmd == "dance":
- for i, msg in enumerate(dancemoves):
- self.setTimeout(i / 2, room.message, msg)
- def onHistoryMessage(self, room, user, message):
- """
- Called when a message gets received from history.
- @type room: Room
- @param room: room where the event occured
- @type user: User
- @param user: owner of message
- @type message: Message
- @param message: the message that got added
- """
- pass
- def onJoin(self, room, user):
- """
- Called when a user joins. Anonymous users get ignored here.
- @type room: Room
- @param room: room where the event occured
- @type user: User
- @param user: the user that has joined
- """
- output = "A known user joined the room.\n\t" + \
- "User:\t" + user.name + "\n\t" + \
- "Time:\t" + self._getShortTimeStamp()
- print(output)
- def onLeave(self, room, user):
- """
- Called when a user leaves. Anonymous users get ignored here.
- @type room: Room
- @param room: room where the event occured
- @type user: User
- @param user: the user that has left
- """
- output = "A known user left the room.\n\t" + \
- "User:\t" + user.name + "\n\t" + \
- "Time:\t" + self._getShortTimeStamp()
- print(output)
- def onRaw(self, room, raw):
- """
- Called before any command parsing occurs.
- @type room: Room
- @param room: room where the event occured
- @type raw: str
- @param raw: raw command data
- """
- pass
- def onPing(self, room):
- """
- Called when a ping gets sent.
- @type room: Room
- @param room: room where the event occured
- """
- output = "Ping sent."
- print(output)
- def onUserCountChange(self, room):
- """
- Called when the user count changes.
- @type room: Room
- @param room: room where the event occured
- """
- output = "There are now " + str(room.getUserCount()) + \
- " members in this room."
- print(output)
- def onBan(self, room, user, target):
- """
- Called when a user gets banned.
- @type room: Room
- @param room: room where the event occured
- @type user: User
- @param user: user that banned someone
- @type target: User
- @param target: user that got banned
- """
- output = "A user has been banned.\n\t" + \
- "Banned:\t" + target.name + "\n\t" + \
- "Banner:\t" + user.name + "\n\t" + \
- "Time:\t" + self._getShortTimeStamp()
- print(output)
- def onUnban(self, room, user, target):
- """
- Called when a user gets unbanned.
- @type room: Room
- @param room: room where the event occured
- @type user: User
- @param user: user that unbanned someone
- @type target: User
- @param target: user that got unbanned
- """
- output = "A user has been unbanned.\n\t" + \
- "Unbanned:\t" + target.name + "\n\t" + \
- "Unbanner:\t" + user.name + "\n\t" + \
- "Time:\t" + self._getShortTimeStamp()
- print(output)
- def onBanlistUpdate(self, room):
- """
- Called when a banlist gets updated.
- @type room: Room
- @param room: room where the event occured
- """
- pass
- def onUnbanlistUpdate(self, room):
- """
- Called when a unbanlist gets updated.
- @type room: Room
- @param room: room where the event occured
- """
- pass
- def onPMConnect(self, pm):
- """
- Called when connected to private chat.
- @type pm: PM
- @param pm: private chat
- """
- output = "Successfully connected to private chat!\t(" + \
- self._getLongTimeStamp() + ")"
- print(output)
- def onPMDisconnect(self, pm):
- """
- Called when disconnected from private chat.
- @type pm: PM
- @param pm: private chat
- """
- output = "Disconnected from private chat.\t(" + \
- self._getLongTimeStamp() + ")"
- print(output)
- def onPMPing(self, pm):
- """
- Called when a ping is sent on private chat.
- @type pm: PM
- @param pm: private chat
- """
- output = "Ping sent."
- print(output)
- def onPMMessage(self, pm, user, body):
- """
- Called when a message is received.
- @type pm: PM
- @param pm: private chat
- @type user: User
- @param user: owner of message
- @type body: str
- @param body: content of the private message
- """
- pass
- def onPMOfflineMessage(self, pm, user, body):
- pass
- def onPMContactlistReceive(self, pm):
- pass
- def onPMBlocklistReceive(self, pm):
- pass
- def onPMContactAdd(self, pm, user):
- """
- Called after a contact is added in private chat.
- @type pm: PM
- @param pm: private chat
- @type user: User
- @param user: new contact
- """
- output = "New contact added in private chat.\n\t" + \
- "User:\t" + user.name + "\n\t" + \
- "Time:\t" + self.getShortTimeStamp()
- print(output)
- def onPMContactRemove(self, pm, user):
- """
- Called after a contact is removed from private chat.
- @type pm: PM
- @param pm: private chat
- @type user: User
- @param user: removed contact
- """
- output = "Existing contact removed from private chat.\n\t" + \
- "User:\t" + user.name + "\n\t" + \
- "Time:\t" + self.getShortTimeStamp()
- print(output)
- def onPMBlock(self, pm, user):
- """
- Called after a user is blocked from contacting the bot via PM.
- @type pm: PM
- @param pm: private chat
- @type user: User
- @param user: blocked user
- """
- output = "User blocked from sending PMs.\n\t" + \
- "User:\t" + user.name + "\n\t" + \
- "Time:\t" + self.getShortTimeStamp()
- print(output)
- def onPMUnblock(self, pm, user):
- """
- Called after a user is repermitted to contact the bot via PM.
- @type pm: PM
- @param pm: private chat
- @type user: User
- @param user: unblocked user
- """
- output = "User unblocked from sending PMs.\n\t" + \
- "User:\t" + user.name + "\n\t" + \
- "Time:\t" + self.getShortTimeStamp()
- print(output)
- def onPMContactOnline(self, pm, user):
- """
- Called when a user in the bot's contact list comes online.
- @type pm: PM
- @param pm: private chat
- @type user: User
- @param user: user who came online
- """
- # Insert code for private messages here
- output = "A user is now online.\n\t" + \
- "User:\t" + user.name + "\n\t" + \
- "Time:\t" + self.getShortTimeStamp()
- print(output)
- def onPMContactOffline(self, pm, user):
- """
- Called when a user in the bot's contact list goes offline.
- @type pm: PM
- @param pm: private chat
- @type user: User
- @param user: user who went offline
- """
- output = "A user has gone offline.\n\t" + \
- "User:\t" + user.name + "\n\t" + \
- "Time:\t" + self.getShortTimeStamp()
- print(output)
- def onEventCalled(self, room, evt, *args, **kw):
- """
- Called on every room-based event.
- @type room: Room
- @param room: room where the event occured
- @type evt: str
- @param evt: the event
- """
- pass
- #####
- # Overridden functions from RoomManager
- #####
- def _getShortTimeStamp(self):
- """
- Returns the time that an event was registered.
- @rtype: str
- @return: timestamp of an event
- """
- return time.strftime("%H:%M:%S UTC", time.gmtime())
- def _getLongTimeStamp(self):
- """
- Returns the date and time when an event took place.
- The local variable "format" may be changed by you the programmer if
- you so desire. To determine how to display the timestamp in your
- preferred manner, please consult the Python documentation at
- http://docs.python.org/library/time.html#time.strftime
- As-is, the formatting would create a time stamp in this style:
- Sunday, Janurary 1 2012, 23:59:59 UTC
- @rtype: str
- @return: timestamp of an event
- """
- # This is the formatting of the time stamp. If it doesn't make sense
- # to you because you aren't from where I am or if you simply just
- # don't like this formatting, please consult the Python documentation
- # at http://docs.python.org/library/time.html#time.strftime
- #
- # As-is, the formatting would create this style of time stamp.
- # Sunday, January 1 2012, 00:00:00 +0:00:00
- format = "%A, %B %d %Y, %H:%M:%S UTC"
- return time.strftime(format, time.gmtime())
- #################################################
- # Run the bot
- #################################################
- manager = MyManager()
- roomList = ["Roms4Droid", "Danball5"] # List of Chatango room names here
- usePM = False # True if you want to PM, False otherwise.
- manager.easy_start(roomList, "R4DBot", "mathias87", usePM)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement