Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- * It joins channels when invited
- * It replies to private messages
- * It (intermittently) speaks in channels when others are speaking
- * It also conveniently presents protocol information on stdout.
- Requires the irc package, obtainable by typing
- pip install irc
- """
- import argparse
- import irc.client
- import irc.events
- import random
- parser = argparse.ArgumentParser(description='Minetrek')
- parser.add_argument('--server', default='localhost',
- help='Server to connect to (defaults to localhost)')
- parser.add_argument('--port', type=int, default=6667,
- help='Port to connect to')
- parser.add_argument('--nick', default='minetrek_help',
- help='Nickname to connect with')
- parser.add_argument('--probability', type=int, default=5,
- help='Probability to reply in channel per message')
- parser.add_argument('--verbose', action='store_true',
- help='Print to stdout all events')
- parser.add_argument('--debug', action='store_true', help='Debug messages')
- options = parser.parse_args()
- def debug(*args):
- "Prints all arguments, if the debug option is enable."
- if options.debug:
- for x in args:
- print x,
- print
- Random = random.Random()
- client = irc.client.IRC()
- server = client.server()
- channellist = []
- # Default event processor
- def process_event(connection, event):
- """
- Prints the parameters of the supplied event: type, arguments, source, and target.
- """
- print "{0}: {1} ({2}->{3})".format(event.type, event.arguments, event.source,
- event.target)
- def pubmsg_handler(connection, event):
- text = event.arguments[0].lower()
- if 'joined the Game' in text:
- user = event.source.split('!')[0]
- connection.privmsg(event.target, "Computer: " + user + ' To visit ships, type /nexus. If you wish to build type /academy and read all the signs.')
- else:
- if 'Trekkie' in text:
- if 'enterprise' in text or 'where is' in text or 'build' in text or 'promote' in text or 'rank' in text or 'self destruct' in text:
- if 'enterprise' in text or 'where is' in text:
- user = event.source.split('!')[0]
- connection.privmsg(event.target, "Computer: " + user + ', type /nexus')
- if 'build' in text or 'promote' in text or 'rank' in text:
- user = event.source.split('!')[0]
- connection.privmsg(event.target, "Computer: " + user + ', type /academy and read the signs')
- if 'self destruct' in text:
- user = event.source.split('!')[0]
- connection.privmsg(event.target, "Computer: " + user + ', Destruct sequence completed and engaged. Awaiting final code for one-minute countdown')
- # else:
- # if 'enterprise' in text or 'where is' in text or 'build' in text or 'promote' in text or 'rank' in text or 'self destruct' in text:
- # if 'enterprise' in text or 'where is' in text:
- # user = event.source.split('!')[0]
- # connection.privmsg(event.target, "Computer: " + user + ', type /nexus')
- # if 'build' in text or 'promote' in text or 'rank' in text:
- # user = event.source.split('!')[0]
- # connection.privmsg(event.target, "Computer: " + user + ', type /academy and read the signs')
- # if 'self destruct' in text:
- # user = event.source.split('!')[0]
- # connection.privmsg(event.target, "Computer: " + user + ', Destruct sequence completed and engaged. Awaiting final code for one-minute countdown')
- # else:
- # if 'computer:' in text:
- # user = event.source.split('!')[0]
- # connection.privmsg(event.target, "Computer: " + user + ', Unknown command.')
- def invite_handler(connection, event):
- """
- Joins a channel when invited.
- """
- for i in event.arguments:
- server.join(i)
- if options.verbose:
- debug('Registering default handler for all messages')
- for v in irc.events.all:
- client.add_global_handler(v, process_event)
- else:
- debug('Registering default handler for protocol messages')
- debug(irc.events.protocol)
- for v in irc.events.protocol:
- client.add_global_handler(v, process_event)
- client.add_global_handler('pubmsg', pubmsg_handler)
- client.add_global_handler('privmsg', privmsg_handler)
- client.add_global_handler('invite', invite_handler)
- server.connect(options.server, options.port, options.nick)
- client.process_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement