Guest User

Untitled

a guest
Sep 9th, 2023
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.49 KB | None | 0 0
  1. import sys
  2. from twisted.internet import defer, endpoints, protocol, reactor, task
  3. from twisted.python import log
  4. from twisted.words.protocols import irc
  5. import random
  6. import time
  7. import requests
  8. from time import sleep
  9. global invader
  10. global hscore
  11. global sscore
  12. global pissd
  13. global started
  14. global uss
  15. global thems
  16. global spoces
  17. spoces = " "
  18. uss = 0
  19. thems = 0
  20. started = 0
  21. pissd = "aaa"
  22. hscore = 0
  23. sscore = 0
  24. invader = 0
  25. dickd = 0
  26. t = 1
  27. et = 666
  28.  
  29. class MyFirstIRCProtocol(irc.IRCClient):
  30.     nickname = 'SpacInvada'
  31.     def __init__(self):
  32.         self.deferred = defer.Deferred()
  33.         self._namescallback = {}
  34.     def connectionLost(self, reason):
  35.         self.deferred.errback(reason)
  36.  
  37.     def signedOn(self):
  38.         # This is called once the server has acknowledged that we sent
  39.         # both NICK and USER.
  40.         for channel in self.factory.channels:
  41.             self.join(channel)
  42.        
  43.     # Obviously, called when a PRIVMSG is received.
  44.     def privmsg(self, user, channel, message):
  45.         global et
  46.         global t
  47.         et = time.time() - t
  48.         if et >=3:
  49.           nick, _, host = user.partition('!')
  50.           message = message.strip()
  51.  
  52.           if not message.startswith('!'):  # not a trigger command
  53.               return  # so do nothing
  54.           command, sep, rest = message.lstrip('!').partition(' ')
  55.           # Get the function corresponding to the command given.
  56.           func = getattr(self, 'command_' + command, None)
  57.           # Or, if there was no function, ignore the message.
  58.           if func is None:
  59.               return
  60.         # maybeDeferred will always return a Deferred. It calls func(rest), and
  61.         # if that returned a Deferred, return that. Otherwise, return the
  62.         # return value of the function wrapped in
  63.         # twisted.internet.defer.succeed. If an exception was raised, wrap the
  64.         # traceback in twisted.internet.defer.fail and return that.
  65.           d = defer.maybeDeferred(func, rest)
  66.         # Add callbacks to deal with whatever the command results are.
  67.         # If the command gives error, the _show_error callback will turn the
  68.         # error into a terse message first:
  69.           d.addErrback(self._showError)
  70.         # Whatever is returned is sent back as a reply:
  71.           if channel == self.nickname:
  72.             # When channel == self.nickname, the message was sent to the bot
  73.             # directly and not to a channel. So we will answer directly too:
  74.             d.addCallback(self._sendMessage, nick)
  75.           else:
  76.             # Otherwise, send the answer to the channel, and use the nick
  77.             # as addressing in the message itself:
  78.             t = time.time()
  79.             d.addCallback(self._sendMessage, channel, nick)
  80.  
  81.     def _sendMessage(self, msg, target, nick=None):
  82.         if nick:
  83.                 msg = '%s, %s' % (nick, msg)
  84.                 self.msg(target, msg)
  85.  
  86.     def _showError(self, failure):
  87.         return failure.getErrorMessage()
  88.  
  89.     def command_ping(self, rest):
  90.         return 'Youre a man.'
  91.  
  92.     ##def command_saylater(self, rest):
  93.         ##when, sep, msg = rest.partition(' ')
  94.         ##when = int(when)
  95.         ##d = defer.Deferred()
  96.         # A small example of how to defer the reply from a command. callLater
  97.         # will callback the Deferred with the reply after so many seconds.
  98.         ##reactor.callLater(when, d.callback, msg)
  99.         # Returning the Deferred here means that it'll be returned from
  100.         # maybeDeferred in privmsg.
  101.         ##return d
  102.  
  103.     def command_start(self, rest):
  104.         global pissd
  105.         global started
  106.         if started == 0:
  107.             started = 1
  108.             ###self.my_function(rest);
  109.             reactor.callInThread(self.my_function, rest);
  110.             return "START"
  111.         else:
  112.             return "THE GAME IS ALREADY STARTED RETARD"
  113.  
  114.     def my_function(self, rest):
  115.         global invader
  116.         global pissd
  117.         global spoces
  118.         sleepytime = random.randint(5,3600)
  119.         sleep(sleepytime);
  120.         invader = 1
  121.         ###self._myfunction2(rest);
  122.         reactor.callInThread(self._myfunction2, rest);
  123.         spacesd = random.randint(0,60)
  124.         spacess=' '
  125.         spoces = spacesd * spacess
  126.         dickd = random.randint(1,7)
  127.         if dickd == 1:
  128.             pissd = "\n"+spoces+"   ▄██▄\n"+spoces+" ▄█▀██▀█▄\n"+spoces+" ▀▀█▀▀█▀▀\n"+spoces+" ▄▀▄▀▀▄▀▄"
  129.         if dickd == 2:
  130.             pissd = "\n"+spoces+" ▄▄▄████▄▄▄\n"+spoces+"███▀▀██▀▀███\n"+spoces+"▀▀▀██▀▀██▀▀▀\n"+spoces+"▄▄▀▀ ▀▀ ▀▀▄▄"
  131.         if dickd == 3:
  132.             pissd = "\n"+spoces+"▄ ▀▄   ▄▀ ▄\n"+spoces+"█▄█▀███▀█▄█\n"+spoces+"▀█████████▀\n"+spoces+" ▄▀     ▀▄"
  133.         if dickd == 4:
  134.             pissd = "\n"+spoces+"   ▄██▄\n"+spoces+" ▄█▀██▀█▄\n"+spoces+" ▀█▀██▀█▀\n"+spoces+" ▀▄    ▄▀"
  135.         if dickd == 5:
  136.             pissd = "\n"+spoces+" ▄▄▄████▄▄▄\n"+spoces+"███▀▀██▀▀███\n"+spoces+"▀▀███▀▀███▀▀\n"+spoces+" ▀█▄ ▀▀ ▄█▀"
  137.         if dickd == 6:
  138.             pissd = "\n"+spoces+"  ▀▄   ▄▀  \n"+spoces+" ▄█▀███▀█▄ \n"+spoces+"███████████\n"+spoces+"▀ ▀▄▄ ▄▄▀ ▀"
  139.         if dickd == 7:
  140.             pissd = "\n"+spoces+"   ▄▄██████▄▄\n"+spoces+" ▄█▀██▀██▀██▀█▄\n"+spoces+"▀▀███▀▀██▀▀███▀▀\n"+spoces+"   ▀        ▀"
  141.         self.msg('#philosophical', pissd)
  142.  
  143.     def _myfunction2(self, rest):
  144.         global invader
  145.         global hscore
  146.         global sscore
  147.         global pissd
  148.         global thems
  149.         global spoces
  150.         sleep(60);
  151.         ###pissd = "\n"+spoces+"     ▄\n"+spoces+"     ▄▀\n"+spoces+"    ▀▄\n"
  152.         ###self.msg('#philosophical', pissd)
  153.         ###sleep(15);
  154.         if invader == 1:
  155.             pissd = "\n"+spoces+"     ▄\n"+spoces+"     ▄▀\n"+spoces+"    ▀▄\n"
  156.             self.msg('#philosophical', pissd)
  157.             sleep(15);
  158.             if invader == 1:
  159.                 invader = 0
  160.                 sscore2 = str(sscore)
  161.                 hscore2 = str(hscore)
  162.                 sscore = 0
  163.                 thems = thems + 1
  164.                 ###self.my_function(rest);
  165.                 reactor.callInThread(self.my_function, rest);
  166.                 pissd2 = "\n"+spoces+"    ▄\n"+spoces+"  ▄    ▄  ▄\n"+spoces+"  ▄ ▀ ▀  ▀ ▀▄\n"+spoces+"▄  ▄▄█▄██▄▄\n"+spoces+"▄▄██████████▄\nGAME OVER\nSCORE "+sscore2+"\nHIGH SCORE "+hscore2
  167.                 ###self.msg('#philosophical', pissd)
  168.                 sleep(1);
  169.                 self.msg('#philosophical', pissd2)
  170.             else:
  171.                 return "h"
  172.         else:
  173.             return "h"
  174.  
  175.     def command_score(self, rest):
  176.         global hscore
  177.         global sscore
  178.         global uss
  179.         global thems
  180.         uss2 = str(uss)
  181.         thems2 = str(thems)
  182.         sscore2 = str(sscore)
  183.         hscore2 = str(hscore)
  184.         pissd = "SCORE "+sscore2+ "\nHIGH SCORE "+hscore2+ "\nPLANET WAR: US "+uss2+" THEM "+thems2
  185.         return pissd
  186.  
  187.     def command_shoot(self,rest):
  188.         global invader
  189.         global sscore
  190.         global pissd
  191.         global hscore
  192.         global uss
  193.         global spoces
  194.         if invader == 1:
  195.             invader = 0
  196.             uss = uss + 1
  197.             sscore = sscore + 1
  198.             if sscore > hscore:
  199.                 hscore = sscore
  200.             sscore2 = str(sscore)
  201.             ###self.my_function(rest);
  202.             reactor.callInThread(self.my_function, rest)
  203.             pissd = "\n"+spoces+" ▄   █  ▄\n"+spoces+"  ▀▄   ▄▀ ▄▀\n"+spoces+"▀▀        ▄▄\n"+spoces+"▄▀ ▄▀   ▀▄\n"+spoces+"   ▀  █   ▀\nSCORE "+sscore2
  204.             return pissd
  205.         else:
  206.             return "WHAT ARE YOU SHOOTING AT RETARD?"
  207.  
  208.     def command_fire(self,rest):
  209.         global invader
  210.         global sscore
  211.         global pissd
  212.         global hscore
  213.         global uss
  214.         global spoces
  215.         if invader == 1:
  216.             invader = 0
  217.             uss = uss + 1
  218.             sscore = sscore + 1
  219.             if sscore > hscore:
  220.                 hscore = sscore
  221.             sscore2 = str(sscore)
  222.             ###self.my_function(rest);
  223.             reactor.callInThread(self.my_function, rest)
  224.             pissd = "\n"+spoces+" ▄   █  ▄\n"+spoces+"  ▀▄   ▄▀ ▄▀\n"+spoces+"▀▀        ▄▄\n"+spoces+"▄▀ ▄▀   ▀▄\n"+spoces+"   ▀  █   ▀\nSCORE "+sscore2
  225.             return pissd
  226.         else:
  227.             return "WHAT ARE YOU SHOOTING AT RETARD?"
  228.  
  229.     def command_bang(self,rest):
  230.         global invader
  231.         global sscore
  232.         global pissd
  233.         global hscore
  234.         global uss
  235.         global spoces
  236.         if invader == 1:
  237.             invader = 0
  238.             uss = uss + 1
  239.             sscore = sscore + 1
  240.             if sscore > hscore:
  241.                 hscore = sscore
  242.             sscore2 = str(sscore)
  243.             ###self.my_function(rest);
  244.             reactor.callInThread(self.my_function, rest)
  245.             pissd = "\n"+spoces+" ▄   █  ▄\n"+spoces+"  ▀▄   ▄▀ ▄▀\n"+spoces+"▀▀        ▄▄\n"+spoces+"▄▀ ▄▀   ▀▄\n"+spoces+"   ▀  █   ▀\nSCORE "+sscore2
  246.             return pissd
  247.         else:
  248.             return "WHAT ARE YOU SHOOTING AT RETARD?"
  249.  
  250.     def command_help(self, rest):
  251.         return "commands !start !shoot !score"
  252.  
  253.     def clientConnectionLost(self, connector, reason):
  254.         #If we get disconnected, reconnect to server."""
  255.         connector.connect()
  256.  
  257.     def clientConnectionFailed(self, connector, reason):
  258.         return "connection failed:", reason
  259.         reactor.stop()
  260.  
  261. class MyFirstIRCFactory(protocol.ReconnectingClientFactory):
  262.     protocol = MyFirstIRCProtocol
  263.     channels = ['#philosophical']
  264.  
  265. def main(reactor, description):
  266.     endpoint = endpoints.clientFromString(reactor, description)
  267.     factory = MyFirstIRCFactory()
  268.     d = endpoint.connect(factory)
  269.     d.addCallback(lambda protocol: protocol.deferred)
  270.     return d
  271.  
  272. if __name__ == '__main__':
  273.     log.startLogging(sys.stderr)
  274.     task.react(main, ['tcp:irc.servercentral.net:6667'])
  275.  
Add Comment
Please, Sign In to add comment