def lookupUserID(user): iter = [] iter.append(userUtils.getID(user)) iter.append(userUtils.getIDSafe(user)) iter.append(userUtils.getIDSafe(user.lower())) iter.append(userUtils.getIDSafe(chat.fixUsernameForIRC(user).lower())) for result in iter: if result: return result
def restrict(fro, chan, message): # Get parameters for i in message: i = i.lower() target = message[0] # Make sure the user exists targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) # Put this user in restricted mode userUtils.restrict(targetUserID) # Send restricted mode packet to this user if he's online targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True) if targetToken is not None: targetToken.setRestricted() requests.get(glob.conf.config["discord"]["krbot"] + "api/v1/submitBanOrRestrict", params={ 'token': glob.conf.config["discord"]["krbotToken"], 'banned': target, 'type': 0, 'author': fro }) log.rap(userID, "has put {} in restricted mode".format(target), True) return "Bye bye {}. See you later, maybe.".format(target)
def ban(fro, chan, message): # Get parameters for i in message: i = i.lower() target = message[0] reason = ' '.join(message[1:]) # Make sure the user exists targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) if targetUserID < 1002 and userID > 1002: return "Nice try." if not reason: return "Please specify a reason for the ban." # Set allowed to 0 userUtils.ban(targetUserID) # Send ban packet to the user if he's online targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True) if targetToken is not None: targetToken.enqueue(serverPackets.loginBanned()) log.rap(userID, "has banned {}".format(target), True) return "RIP {}. You will not be missed.".format(target)
def mp_removeRef(): userID = userUtils.getID(fro) if not can_user_touch_lobby(get_match_id_from_channel(chan), userID, False, False): return False if len(message) < 2: raise exceptions.invalidArgumentsException( "Wrong syntax: !mp removeref <ref username>") userRefID = userUtils.getIDSafe(message[1]) if not userRefID: raise exceptions.invalidArgumentsException("User not found") _match = glob.matches.matches[get_match_id_from_channel(chan)] if not userRefID in _match.refs: return "This user is not referre." _match.refs.remove(userRefID) _match.sendUpdates() chat.partChannel(userRefID, "#multi_{}".format(_match.matchID), kick=True) chat.partChannel(userRefID, "#multiplayer", kick=True) return "Match referre was deleted!"
def mp_addRef(): userID = userUtils.getID(fro) if not can_user_touch_lobby(get_match_id_from_channel(chan), userID, False, False): return False if len(message) < 2: raise exceptions.invalidArgumentsException( "Wrong syntax: !mp addref <ref username>") # check is correct nickname userID = userUtils.getID(fro) userRefID = userUtils.getIDSafe(message[1]) if not userRefID: raise exceptions.invalidArgumentsException("User not found") if userID == userRefID: return False tokens = glob.tokens.getTokenFromUsername(userUtils.safeUsername( message[1]), safe=True, _all=True) if len(tokens) == 0: return "{} is not online".format(message[1]) _match = glob.matches.matches[get_match_id_from_channel(chan)] if userRefID in _match.refs: return "This referre added already :) He can join with command !mp join {}".format( _match.matchID) _match.refs.append(userRefID) _match.sendUpdates() return "Added {} to match referre. He can join with command !mp join {}".format( userRefID, _match.matchID)
def mp_invite(): userID = userUtils.getID(fro) if not can_user_touch_lobby(get_match_id_from_channel(chan), userID, True): return False if len(message) < 2: raise exceptions.invalidArgumentsException( "Wrong syntax: !mp invite <username>") username = message[1].strip() if not username: raise exceptions.invalidArgumentsException( "Please provide a username") userID = userUtils.getIDSafe(username) if userID is None: raise exceptions.userNotFoundException("No such user") token = glob.tokens.getTokenFromUserID(userID, ignoreIRC=True) if token is None: raise exceptions.invalidUserException( "That user is not connected to bancho right now.") _match = glob.matches.matches[get_match_id_from_channel(chan)] _match.invite(999, userID) token.enqueue( serverPackets.notification( "Please accept the invite you've just received from {} to " "enter your tourney match.".format(glob.BOT_NAME))) return "An invite to this match has been sent to {}".format(username)
def ban(fro, chan, message): # Get parameters for i in message: i = i.lower() target = message[0] # Make sure the user exists targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) # Set allowed to 0 userUtils.ban(targetUserID) # Send ban packet to the user if he's online targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True) if targetToken is not None: targetToken.enqueue(serverPackets.loginBanned()) # Posting to discord requests.get(glob.conf.config["discord"]["krbot"] + "api/v1/submitBanOrRestrict", params={ 'token': glob.conf.config["discord"]["krbotToken"], 'banned': target, 'type': 1, 'author': fro }) log.rap(userID, "has banned {}".format(target), True) return "RIP {}. You will not be missed.".format(target)
def rtx(fro, chan, message): target = message[0] message = " ".join(message[1:]).strip() if not message: return "Invalid message" targetUserID = userUtils.getIDSafe(target) if not targetUserID: return "{}: user not found".format(target) userToken = glob.tokens.getTokenFromUserID(targetUserID, ignoreIRC=True, _all=False) userToken.enqueue(serverPackets.rtx(message)) return ":ok_hand:"
def mpHost(): if len(message) < 2: raise exceptions.invalidArgumentsException("Wrong syntax: !mp host <username>") username = message[1].strip() if not username: raise exceptions.invalidArgumentsException("Please provide a username") userID = userUtils.getIDSafe(username) if userID is None: raise exceptions.userNotFoundException("No such user") _match = glob.matches.matches[getMatchIDFromChannel(chan)] success = _match.setHost(userID) return "{} is now the host".format(username) if success else "Couldn't give host to {}".format(username)
def restrict(fro, chan, message): # Get parameters for i in message: i = i.lower() target = message[0] reason = ' '.join(message[1:]) # Make sure the user exists targetUserID = userUtils.getIDSafe(target) username = chat.fixUsernameForBancho(fro) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) if targetUserID < 1002 and userID > 1002: log.enjuu("{} attempted to restrict immortal user {}.".format(username, targetUserID), discord="cm") return "Nice try." if not reason: reason = "not avialable" # Put this user in restricted mode userUtils.restrict(targetUserID) # Send restricted mode packet to this user if he's online targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True) if targetToken is not None: targetToken.setRestricted() log.rap(userID, "has restricted {} ({}) for: {}".format(target, targetUserID, reason), True) hook = Webhook(glob.conf.config["discord"]["webhook"]) embed = Embed( description='', color=0x1e0f3, timestamp='now' # sets the timestamp to current time ) avatar = "https://a.enjuu.click/" embed.set_author(name='Restriction', icon_url="https://a.enjuu.click/{}".format(targetUserID)) embed.add_field(name='Username', value="{}".format(target)) embed.add_field(name='Reason', value="{}".format(reason)) embed.set_footer(text="Restricted by {}".format(username)) embed.set_thumbnail("https://a.enjuu.click/{}".format(targetUserID)) hook.send(embed=embed) return "{} has been restricted for {}".format(target, reason)
def asyncGet(self): try: # Get request ip ip = self.getRequestIP() # Check arguments if not requestsManager.checkArguments(self.request.arguments, ["c", "u", "h"]): raise exceptions.invalidArgumentsException(MODULE_NAME) # Get arguments username = self.get_argument("u") password = self.get_argument("h") replayID = self.get_argument("c") # Login check userID = userUtils.getID(username) if userID == 0: raise exceptions.loginFailedException(MODULE_NAME, userID) if not userUtils.checkLogin(userID, password, ip): raise exceptions.loginFailedException(MODULE_NAME, username) if userUtils.check2FA(userID, ip): raise exceptions.need2FAException(MODULE_NAME, username, ip) # Get user ID replayData = glob.db.fetch("SELECT scores.*, users.username AS uname FROM scores LEFT JOIN users ON scores.userid = users.id WHERE scores.id = %s", [replayID]) # Increment 'replays watched by others' if needed immuneUsers = [1001, 1002, 1028] UserID = userUtils.getIDSafe(username) if replayData is not None: if username != replayData["uname"]: if userID not in immuneUsers: userUtils.incrementReplaysWatched(replayData["userid"], replayData["play_mode"], replayData["mods"]) # Serve replay log.info("Serving replay_{}.osr".format(replayID)) fileName = ".data/replays/replay_{}.osr".format(replayID) if os.path.isfile(fileName): with open(fileName, "rb") as f: fileContent = f.read() self.write(fileContent) else: log.warning("Replay {} doesn't exist".format(replayID)) self.write("") except exceptions.invalidArgumentsException: pass except exceptions.need2FAException: pass except exceptions.loginFailedException: pass
def silence(fro, chan, message): message = [x.lower() for x in message] target = message[0] amount = message[1] unit = message[2] reason = ' '.join(message[3:]).strip() if not reason: return "Please provide a valid reason." if not amount.isdigit(): return "The amount must be a number." # Get target user ID targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) # Make sure the user exists if not targetUserID: return "{}: user not found".format(target) # Calculate silence seconds if unit == 's': silenceTime = int(amount) elif unit == 'm': silenceTime = int(amount) * 60 elif unit == 'h': silenceTime = int(amount) * 3600 elif unit == 'd': silenceTime = int(amount) * 86400 else: return "Invalid time unit (s/m/h/d)." # Max silence time is 7 days if silenceTime > 604800: return "Invalid silence time. Max silence time is 7 days." # Send silence packet to target if he's connected targetToken = glob.tokens.getTokenFromUsername( userUtils.safeUsername(target), safe=True) if targetToken is not None: # user online, silence both in db and with packet targetToken.silence(silenceTime, reason, userID) else: # User offline, silence user only in db userUtils.silence(targetUserID, silenceTime, reason, userID) # Log message msg = "{} has been silenced for the following reason: {}".format( target, reason) return msg
def mpTeam(): if len(message) < 3: raise exceptions.invalidArgumentsException("Wrong syntax: !mp team <username> <colour>") username = message[1].strip() if not username: raise exceptions.invalidArgumentsException("Please provide a username") colour = message[2].lower().strip() if colour not in ["red", "blue"]: raise exceptions.invalidArgumentsException("Team colour must be red or blue") userID = userUtils.getIDSafe(username) if userID is None: raise exceptions.userNotFoundException("No such user") _match = glob.matches.matches[getMatchIDFromChannel(chan)] _match.changeTeam(userID, matchTeams.BLUE if colour == "blue" else matchTeams.RED) return "{} is now in {} team".format(username, colour)
def mpMove(): if len(message) < 3 or not message[2].isdigit() or int(message[2]) < 0 or int(message[2]) > 16: raise exceptions.invalidArgumentsException("Wrong syntax: !mp move <username> <slot>") username = message[1] newSlotID = int(message[2]) userID = userUtils.getIDSafe(username) if userID is None: raise exceptions.userNotFoundException("No such user") _match = glob.matches.matches[getMatchIDFromChannel(chan)] success = _match.userChangeSlot(userID, newSlotID) if success: result = "Player {} moved to slot {}".format(username, newSlotID) else: result = "You can't use that slot: it's either already occupied by someone else or locked" return result
def mpKick(): if len(message) < 2: raise exceptions.invalidArgumentsException( "Wrong syntax: !mp kick <username>") username = message[1] userID = userUtils.getIDSafe(username) if userID is None: raise exceptions.userNotFoundException("No such user") _match = glob.matches.matches[getMatchIDFromChannel(chan)] slotID = _match.getUserSlotID(userID) if slotID is None: raise exceptions.userNotFoundException( "The specified user is not in this match") for i in range(0, 2): _match.toggleSlotLocked(slotID) return "{} has been kicked from the match.".format(username)
def kill(fro, chan, message): for i in message: i = i.lower() target = message[0] targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) targetToken = glob.tokens.getTokenFromUserID(targetUserID) targetToken.enqueue(serverPackets.userSupporterGMT(True, False, False)) targetToken.enqueue(serverPackets.userSupporterGMT(False, True, False)) targetToken.enqueue(serverPackets.kill()) return "{} has been killed".format(target)
def unrestrict(fro, chan, message): # Get parameters for i in message: i = i.lower() target = message[0] # Make sure the user exists targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) # Set allowed to 1 userUtils.unrestrict(targetUserID) log.rap(userID, "has removed restricted mode from {}".format(target), True) return "Welcome back {}!".format(target)
def mpInvite(): if len(message) < 2: raise exceptions.invalidArgumentsException( "Wrong syntax: !mp invite <username>") username = message[1] userID = userUtils.getIDSafe(username) if userID is None: raise exceptions.userNotFoundException("No such user") token = glob.tokens.getTokenFromUserID(userID, ignoreIRC=True) if token is None: raise exceptions.invalidUserException( "That user is not connected to bancho right now.") _match = glob.matches.matches[getMatchIDFromChannel(chan)] _match.invite(999, userID) token.enqueue( serverPackets.notification( "Please accept the invite you've just received from FokaBot to " "enter your tourney match.")) return "An invite to this match has been sent to {}".format(username)
def switchServer(fro, chan, message): # Get target user ID target = message[0] newServer = message[1] targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) # Make sure the user exists if not targetUserID: return "{}: user not found".format(target) # Connect the user to the end server userToken = glob.tokens.getTokenFromUserID(userID, ignoreIRC=True, _all=False) userToken.enqueue(serverPackets.switchServer(newServer)) # Disconnect the user from the origin server # userToken.kick() return "{} has been connected to {}".format(target, newServer)
def lock_user(fro, chan, message): # Get parameters for i in message: i = i.lower() target = message[0] # Make sure the user exists targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) # only lock client now ;d #userUtils.ban(targetUserID) targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True) if targetToken is not None: targetToken.enqueue(serverPackets.banClient()) return "RIP {}. Now he have locked osu!client!".format(target)
def removeSilence(fro, chan, message): # Get parameters for i in message: i = i.lower() target = message[0] # Make sure the user exists targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) # Send new silence end packet to user if he's online targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True) if targetToken is not None: # User online, remove silence both in db and with packet targetToken.silence(0, "", userID) else: # user offline, remove islene ofnlt from db userUtils.silence(targetUserID, 0, "", userID) return "{}'s silence reset".format(target)
def restrict(fro, chan, message): # Get parameters for i in message: i = i.lower() target = message[0] # Make sure the user exists targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) # Put this user in restricted mode userUtils.restrict(targetUserID) # Send restricted mode packet to this user if he's online targetToken = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True) if targetToken is not None: targetToken.setRestricted() log.rap(userID, "has put {} in restricted mode".format(target), True) return "Bye bye {}. See you later, maybe.".format(target)
def unrestrict(fro, chan, message): # Get parameters for i in message: i = i.lower() target = message[0] # Make sure the user exists targetUserID = userUtils.getIDSafe(target) userID = userUtils.getID(fro) if not targetUserID: return "{}: user not found".format(target) # Set allowed to 1 userUtils.unrestrict(targetUserID) requests.get(glob.conf.config["discord"]["krbot"] + "api/v1/submitBanOrRestrict", params={ 'token': glob.conf.config["discord"]["krbotToken"], 'banned': target, 'type': 2, 'author': fro }) log.rap(userID, "has removed restricted mode from {}".format(target), True) return "Welcome back {}!".format(target)
def mp_kick(): userID = userUtils.getID(fro) if not can_user_touch_lobby(get_match_id_from_channel(chan), userID, False, False): return False if len(message) < 2: raise exceptions.invalidArgumentsException( "Wrong syntax: !mp kick <username>") username = message[1].strip() if not username: raise exceptions.invalidArgumentsException( "Please provide a username") userID = userUtils.getIDSafe(username) if userID is None: raise exceptions.userNotFoundException("No such user") _match = glob.matches.matches[get_match_id_from_channel(chan)] slotID = _match.getUserSlotID(userID) if slotID is None: raise exceptions.userNotFoundException( "The specified user is not in this match") for i in range(0, 2): _match.toggleSlotLocked(slotID) return "{} has been kicked from the match.".format(username)