Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from twisted.internet import defer, endpoints, protocol, reactor, task
- from twisted.python import log
- from twisted.words.protocols import irc
- import random
- import time
- import requests
- from time import sleep
- global invader
- global hscore
- global sscore
- global pissd
- global started
- global uss
- global thems
- global spoces
- spoces = " "
- uss = 0
- thems = 0
- started = 0
- pissd = "aaa"
- hscore = 0
- sscore = 0
- invader = 0
- dickd = 0
- t = 1
- et = 666
- class MyFirstIRCProtocol(irc.IRCClient):
- nickname = 'SpacInvada'
- def __init__(self):
- self.deferred = defer.Deferred()
- self._namescallback = {}
- def connectionLost(self, reason):
- self.deferred.errback(reason)
- def signedOn(self):
- # This is called once the server has acknowledged that we sent
- # both NICK and USER.
- for channel in self.factory.channels:
- self.join(channel)
- # Obviously, called when a PRIVMSG is received.
- def privmsg(self, user, channel, message):
- global et
- global t
- et = time.time() - t
- if et >=3:
- nick, _, host = user.partition('!')
- message = message.strip()
- if not message.startswith('!'): # not a trigger command
- return # so do nothing
- command, sep, rest = message.lstrip('!').partition(' ')
- # Get the function corresponding to the command given.
- func = getattr(self, 'command_' + command, None)
- # Or, if there was no function, ignore the message.
- if func is None:
- return
- # maybeDeferred will always return a Deferred. It calls func(rest), and
- # if that returned a Deferred, return that. Otherwise, return the
- # return value of the function wrapped in
- # twisted.internet.defer.succeed. If an exception was raised, wrap the
- # traceback in twisted.internet.defer.fail and return that.
- d = defer.maybeDeferred(func, rest)
- # Add callbacks to deal with whatever the command results are.
- # If the command gives error, the _show_error callback will turn the
- # error into a terse message first:
- d.addErrback(self._showError)
- # Whatever is returned is sent back as a reply:
- if channel == self.nickname:
- # When channel == self.nickname, the message was sent to the bot
- # directly and not to a channel. So we will answer directly too:
- d.addCallback(self._sendMessage, nick)
- else:
- # Otherwise, send the answer to the channel, and use the nick
- # as addressing in the message itself:
- t = time.time()
- d.addCallback(self._sendMessage, channel, nick)
- def _sendMessage(self, msg, target, nick=None):
- if nick:
- msg = '%s, %s' % (nick, msg)
- self.msg(target, msg)
- def _showError(self, failure):
- return failure.getErrorMessage()
- def command_ping(self, rest):
- return 'Youre a man.'
- ##def command_saylater(self, rest):
- ##when, sep, msg = rest.partition(' ')
- ##when = int(when)
- ##d = defer.Deferred()
- # A small example of how to defer the reply from a command. callLater
- # will callback the Deferred with the reply after so many seconds.
- ##reactor.callLater(when, d.callback, msg)
- # Returning the Deferred here means that it'll be returned from
- # maybeDeferred in privmsg.
- ##return d
- def command_start(self, rest):
- global pissd
- global started
- if started == 0:
- started = 1
- ###self.my_function(rest);
- reactor.callInThread(self.my_function, rest);
- return "START"
- else:
- return "THE GAME IS ALREADY STARTED RETARD"
- def my_function(self, rest):
- global invader
- global pissd
- global spoces
- sleepytime = random.randint(5,3600)
- sleep(sleepytime);
- invader = 1
- ###self._myfunction2(rest);
- reactor.callInThread(self._myfunction2, rest);
- spacesd = random.randint(0,60)
- spacess=' '
- spoces = spacesd * spacess
- dickd = random.randint(1,7)
- if dickd == 1:
- pissd = "\n"+spoces+" ▄██▄\n"+spoces+" ▄█▀██▀█▄\n"+spoces+" ▀▀█▀▀█▀▀\n"+spoces+" ▄▀▄▀▀▄▀▄"
- if dickd == 2:
- pissd = "\n"+spoces+" ▄▄▄████▄▄▄\n"+spoces+"███▀▀██▀▀███\n"+spoces+"▀▀▀██▀▀██▀▀▀\n"+spoces+"▄▄▀▀ ▀▀ ▀▀▄▄"
- if dickd == 3:
- pissd = "\n"+spoces+"▄ ▀▄ ▄▀ ▄\n"+spoces+"█▄█▀███▀█▄█\n"+spoces+"▀█████████▀\n"+spoces+" ▄▀ ▀▄"
- if dickd == 4:
- pissd = "\n"+spoces+" ▄██▄\n"+spoces+" ▄█▀██▀█▄\n"+spoces+" ▀█▀██▀█▀\n"+spoces+" ▀▄ ▄▀"
- if dickd == 5:
- pissd = "\n"+spoces+" ▄▄▄████▄▄▄\n"+spoces+"███▀▀██▀▀███\n"+spoces+"▀▀███▀▀███▀▀\n"+spoces+" ▀█▄ ▀▀ ▄█▀"
- if dickd == 6:
- pissd = "\n"+spoces+" ▀▄ ▄▀ \n"+spoces+" ▄█▀███▀█▄ \n"+spoces+"███████████\n"+spoces+"▀ ▀▄▄ ▄▄▀ ▀"
- if dickd == 7:
- pissd = "\n"+spoces+" ▄▄██████▄▄\n"+spoces+" ▄█▀██▀██▀██▀█▄\n"+spoces+"▀▀███▀▀██▀▀███▀▀\n"+spoces+" ▀ ▀"
- self.msg('#philosophical', pissd)
- def _myfunction2(self, rest):
- global invader
- global hscore
- global sscore
- global pissd
- global thems
- global spoces
- sleep(60);
- ###pissd = "\n"+spoces+" ▄\n"+spoces+" ▄▀\n"+spoces+" ▀▄\n"
- ###self.msg('#philosophical', pissd)
- ###sleep(15);
- if invader == 1:
- pissd = "\n"+spoces+" ▄\n"+spoces+" ▄▀\n"+spoces+" ▀▄\n"
- self.msg('#philosophical', pissd)
- sleep(15);
- if invader == 1:
- invader = 0
- sscore2 = str(sscore)
- hscore2 = str(hscore)
- sscore = 0
- thems = thems + 1
- ###self.my_function(rest);
- reactor.callInThread(self.my_function, rest);
- pissd2 = "\n"+spoces+" ▄\n"+spoces+" ▄ ▄ ▄\n"+spoces+" ▄ ▀ ▀ ▀ ▀▄\n"+spoces+"▄ ▄▄█▄██▄▄\n"+spoces+"▄▄██████████▄\nGAME OVER\nSCORE "+sscore2+"\nHIGH SCORE "+hscore2
- ###self.msg('#philosophical', pissd)
- sleep(1);
- self.msg('#philosophical', pissd2)
- else:
- return "h"
- else:
- return "h"
- def command_score(self, rest):
- global hscore
- global sscore
- global uss
- global thems
- uss2 = str(uss)
- thems2 = str(thems)
- sscore2 = str(sscore)
- hscore2 = str(hscore)
- pissd = "SCORE "+sscore2+ "\nHIGH SCORE "+hscore2+ "\nPLANET WAR: US "+uss2+" THEM "+thems2
- return pissd
- def command_shoot(self,rest):
- global invader
- global sscore
- global pissd
- global hscore
- global uss
- global spoces
- if invader == 1:
- invader = 0
- uss = uss + 1
- sscore = sscore + 1
- if sscore > hscore:
- hscore = sscore
- sscore2 = str(sscore)
- ###self.my_function(rest);
- reactor.callInThread(self.my_function, rest)
- pissd = "\n"+spoces+" ▄ █ ▄\n"+spoces+" ▀▄ ▄▀ ▄▀\n"+spoces+"▀▀ ▄▄\n"+spoces+"▄▀ ▄▀ ▀▄\n"+spoces+" ▀ █ ▀\nSCORE "+sscore2
- return pissd
- else:
- return "WHAT ARE YOU SHOOTING AT RETARD?"
- def command_fire(self,rest):
- global invader
- global sscore
- global pissd
- global hscore
- global uss
- global spoces
- if invader == 1:
- invader = 0
- uss = uss + 1
- sscore = sscore + 1
- if sscore > hscore:
- hscore = sscore
- sscore2 = str(sscore)
- ###self.my_function(rest);
- reactor.callInThread(self.my_function, rest)
- pissd = "\n"+spoces+" ▄ █ ▄\n"+spoces+" ▀▄ ▄▀ ▄▀\n"+spoces+"▀▀ ▄▄\n"+spoces+"▄▀ ▄▀ ▀▄\n"+spoces+" ▀ █ ▀\nSCORE "+sscore2
- return pissd
- else:
- return "WHAT ARE YOU SHOOTING AT RETARD?"
- def command_bang(self,rest):
- global invader
- global sscore
- global pissd
- global hscore
- global uss
- global spoces
- if invader == 1:
- invader = 0
- uss = uss + 1
- sscore = sscore + 1
- if sscore > hscore:
- hscore = sscore
- sscore2 = str(sscore)
- ###self.my_function(rest);
- reactor.callInThread(self.my_function, rest)
- pissd = "\n"+spoces+" ▄ █ ▄\n"+spoces+" ▀▄ ▄▀ ▄▀\n"+spoces+"▀▀ ▄▄\n"+spoces+"▄▀ ▄▀ ▀▄\n"+spoces+" ▀ █ ▀\nSCORE "+sscore2
- return pissd
- else:
- return "WHAT ARE YOU SHOOTING AT RETARD?"
- def command_help(self, rest):
- return "commands !start !shoot !score"
- def clientConnectionLost(self, connector, reason):
- #If we get disconnected, reconnect to server."""
- connector.connect()
- def clientConnectionFailed(self, connector, reason):
- return "connection failed:", reason
- reactor.stop()
- class MyFirstIRCFactory(protocol.ReconnectingClientFactory):
- protocol = MyFirstIRCProtocol
- channels = ['#philosophical']
- def main(reactor, description):
- endpoint = endpoints.clientFromString(reactor, description)
- factory = MyFirstIRCFactory()
- d = endpoint.connect(factory)
- d.addCallback(lambda protocol: protocol.deferred)
- return d
- if __name__ == '__main__':
- log.startLogging(sys.stderr)
- task.react(main, ['tcp:irc.servercentral.net:6667'])
Add Comment
Please, Sign In to add comment