MeKLiN2

register.py

Mar 21st, 2022
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. # User Level Registration
  2. # Banned Account Check
  3. # VIP Mode Check
  4. # Guest Mode
  5. # Lurker Mode
  6.  
  7. # Odsum
  8.  
  9. import pinylib
  10. import time
  11. from time import sleep
  12. import random
  13. from random import randint
  14. from apis import tinychat
  15.  
  16.  
  17. class Registration:
  18.  
  19. def __init__(self, tinybot, spamcheck, conf):
  20. """
  21. Initialize the Spam class.
  22.  
  23. :param tinybot: An instance of TinychatBot.
  24. :type tinybot: TinychatBot
  25. :param spamcheck: check if room is in lockdown
  26. :type spamcheck: True/False
  27. :param conf: The config file.
  28. :type conf: config
  29. """
  30. self.tinybot = tinybot
  31. self.spamcheck = spamcheck
  32. self.config = conf
  33. self.lockdown = False
  34. self.greet = None
  35.  
  36. def user_register(self, _user):
  37.  
  38. if not _user.account:
  39. _user.user_level = 7 # guest
  40. self.tinybot.console_write(pinylib.COLOR['cyan'],
  41. '[User] Guest %s:%d' % (_user.nick, _user.id))
  42.  
  43. if not self.config.B_ALLOW_GUESTS:
  44. if _user.user_level == 7:
  45. if self.spamcheck.lockdown:
  46. self.tinybot.process_ban(_user.id)
  47. else:
  48. self.tinybot.send_ban_msg(_user.id)
  49. if self.config.B_VERBOSE:
  50. self.tinybot.handle_msg('%s was banned (No Guests allowed).' % _user.nick)
  51. self.tinybot.console_write(pinylib.COLOR['red'],
  52. '[Security] %s was banned on no guest mode' % _user.nick)
  53. return False
  54.  
  55. if _user.is_lurker and not self.config.B_ALLOW_LURKERS:
  56. if _user.user_level > 5:
  57. if self.spamcheck.lockdown:
  58. self.tinybot.process_ban(_user.id)
  59. else:
  60. self.tinybot.send_ban_msg(_user.id)
  61. if self.config.B_VERBOSE:
  62. self.tinybot.handle_msg('%s is a lurker, no captcha. No Lurker Mode' % _user.nick)
  63. self.tinybot.console_write(pinylib.COLOR['red'],
  64. '[Security] %s was banned on no lurkers mode' % _user.nick)
  65. return False
  66.  
  67. else:
  68.  
  69. buddyusr = self.tinybot.buddy_db.find_db_user(_user.account)
  70. tc_info = tinychat.user_info(_user.account)
  71.  
  72. if tc_info is not None:
  73. _user.tinychat_id = tc_info['tinychat_id']
  74. _user.last_login = tc_info['last_active']
  75. self.greet = tc_info['biography']
  76.  
  77. if _user.is_owner:
  78. _user.user_level = 2 # account owner
  79. self.tinybot.console_write(pinylib.COLOR['cyan'], '[User] Room Owner %s:%d:%s' %
  80. (_user.nick, _user.id, _user.account))
  81. elif _user.is_mod:
  82. _user.user_level = 3 # mod
  83. self.tinybot.console_write(pinylib.COLOR['cyan'], '[User] Moderator %s:%d:%s' %
  84. (_user.nick, _user.id, _user.account))
  85.  
  86. if buddyusr:
  87. _level = buddyusr['level']
  88.  
  89. if not _user.is_mod:
  90. _user.user_level = _level
  91.  
  92. if _level < 6:
  93. if buddyusr['greet'] != '':
  94. self.greet = buddyusr['greet']
  95.  
  96. if _level == 4 and not _user.is_mod:
  97. _user.user_level = _level # chatmod
  98.  
  99. if _level == 5 and not _user.is_mod:
  100. _user.user_level = _level # whitelist
  101.  
  102. if _level == 2: # overwrite mod to chatadmin
  103. _user.user_level = _level
  104.  
  105. self.tinybot.console_write(pinylib.COLOR['cyan'], '[User] Found, level(%s) %s:%d:%s' % (
  106. _user.user_level, _user.nick, _user.id, _user.account))
  107.  
  108. if self.tinybot.buddy_db.find_db_account_bans(_user.account) and self.tinybot.is_client_mod:
  109. if self.spamcheck.lockdown:
  110. self.tinybot.process_ban(_user.id)
  111. else:
  112. self.tinybot.process_ban(_user.id)
  113. if self.config.B_VERBOSE:
  114. self.tinybot.handle_msg('%s is an banned account.' % _user.account)
  115. self.tinybot.console_write(pinylib.COLOR['red'],
  116. '[Security] Banned: Account %s' % _user.account)
  117. return False
  118.  
  119. if _user.user_level is None:
  120. _user.user_level = 6 # account not whitelisted
  121. self.tinybot.console_write(pinylib.COLOR['cyan'],
  122. '[User] Not Whitelisted %s:%d:%s' % (_user.nick, _user.id, _user.account))
  123.  
  124. if self.config.B_VIP and not buddyusr:
  125. if self.spamcheck.lockdown:
  126. self.tinybot.process_ban(_user.id)
  127. else:
  128. sleep(randint(10,20))
  129. self.tinybot.send_ban_msg(_user.id)
  130.  
  131. if self.config.B_VERBOSE:
  132. self.tinybot.handle_msg(
  133. '%s is banned account, only known accounts allowed in VIP Mode.' % _user.account)
  134. self.tinybot.console_write(pinylib.COLOR['red'],
  135. '[Security] %s was banned, VIP mode' % _user.nick)
  136. return False
  137. return True
Advertisement
Add Comment
Please, Sign In to add comment