Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Chat in Console by unihernandez22

a guest Apr 5th, 2020 276 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import logging
  2. import sys
  3. from datetime import date, datetime
  4. import random
  5.  
  6. from irc.bot import SingleServerIRCBot
  7.  
  8. from colorama import Fore, Back, Style
  9. colored = lambda text, *args: f"{''.join(args)}{text}{Style.RESET_ALL}"
  10.  
  11. # config
  12. HOST = 'irc.twitch.tv'
  13. PORT = 6667
  14. USERNAME = 'bot'
  15. PASSWORD = 'TOKEN'  # http://www.twitchapps.com/tmi/
  16. CHANNEL = '#vicfred'
  17.  
  18.  
  19. def _get_logger():
  20.     logger_name = 'vbot'
  21.     logger_level = logging.DEBUG
  22.     log_line_format = '%(asctime)s | %(name)s - %(levelname)s : %(message)s'
  23.     log_line_date_format = '%Y-%m-%dT%H:%M:%SZ'
  24.     logger_ = logging.getLogger(logger_name)
  25.     logger_.setLevel(logger_level)
  26.     logging_handler = logging.StreamHandler(stream=sys.stdout)
  27.     logging_handler.setLevel(logger_level)
  28.     logging_formatter = logging.Formatter(log_line_format, datefmt=log_line_date_format)
  29.     logging_handler.setFormatter(logging_formatter)
  30.     logger_.addHandler(logging_handler)
  31.     return logger_
  32.  
  33. logger = _get_logger()
  34.  
  35.  
  36. class VBot(SingleServerIRCBot):
  37.     VERSION = '1.0.0'
  38.  
  39.     def __init__(self, host, port, nickname, password, channel):
  40.         logger.debug('VBot.__init__ (VERSION = %r)', self.VERSION)
  41.         SingleServerIRCBot.__init__(self, [(host, port, password)], nickname, nickname)
  42.         self.channel = channel
  43.         self.colors = [Fore.RED, Fore.BLUE, Fore.GREEN, Fore.CYAN, Fore.YELLOW, Fore.MAGENTA]
  44.         self.viewers = {}
  45.         self.filename = f'stream-{date.today()}.txt'
  46.  
  47.     def on_welcome(self, connection, event):
  48.         logger.debug('VBot.on_welcome')
  49.         connection.join(self.channel)
  50.         connection.privmsg(event.target, 'Hola!')
  51.  
  52.     def on_join(self, connection, event):
  53.         logger.debug('VBot.on_join')
  54.         nickname = self._parse_nickname_from_twitch_user_id(event.source)
  55.         self.viewers[nickname] = random.choice(self.colors)
  56.  
  57.         # if nickname.lower() == connection.get_nickname().lower():
  58.         #     connection.privmsg(event.target, f'Hola {nickname.lower()}!')
  59.  
  60.     def on_part(self, connection, event):
  61.         logger.debug('VBot.on_part')
  62.         nickname = self._parse_nickname_from_twitch_user_id(event.source)
  63.         del self.viewers[nickname]
  64.  
  65.     def on_pubmsg(self, connection, event):
  66.         # logger.debug('VBot.on_pubmsg')
  67.         message = event.arguments[0]
  68.         nickname = self._parse_nickname_from_twitch_user_id(event.source)
  69.         t = datetime.now()
  70.  
  71.         if 'vicfred' in message.lower():
  72.             print(colored('ATENTION! ', Fore.RED, Style.BRIGHT), end='')
  73.  
  74.         try:
  75.             print(f'{t.hour:02}:{t.minute:02} <{colored(nickname, self.viewers[nickname])}> {message}')
  76.         except KeyError:
  77.             self.viewers[nickname] = random.choice(self.colors)
  78.             print(f'{t.hour:02}:{t.minute:02} <{colored(nickname, self.viewers[nickname])}> {message}')
  79.  
  80.         with open(self.filename, 'a') as file:
  81.             file.write(f'{nickname}: {message}\n')
  82.             file.close()
  83.  
  84.         if 'hola' in message.lower():
  85.             self.connection.privmsg(event.target, f'Hola {nickname}!')
  86.         elif message == '!viewers':
  87.             self.connection.privmsg(event.target, f'Hay {len(self.viewers)} viewers')
  88.         elif message == '!version':
  89.             self.connection.privmsg(event.target, f'Version: {self.VERSION}')
  90.  
  91.     @staticmethod
  92.     def _parse_nickname_from_twitch_user_id(user_id):
  93.         # nickname!username@nickname.tmi.twitch.tv
  94.         return user_id.split('!', 1)[0]
  95.  
  96.  
  97. def main():
  98.     my_bot = VBot(HOST, PORT, USERNAME, PASSWORD, CHANNEL)
  99.     my_bot.start()
  100.  
  101.  
  102. if __name__ == '__main__':
  103.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top