Exemple #1
0
def report(fro, chan, message):
    msg = ""
    try:
        # TODO: Rate limit
        # Get username, report reason and report info
        target, reason, additionalInfo = message[0], message[1], message[2]
        target = chat.fixUsernameForBancho(target)

        # Make sure the target is not foka
        if target == glob.BOT_NAME:
            raise exceptions.invalidUserException()

        # Make sure the user exists
        targetID = userUtils.getID(target)
        if targetID == 0:
            raise exceptions.userNotFoundException()

        # Make sure that the user has specified additional info if report reason is 'Other'
        if reason.lower() == "other" and not additionalInfo:
            raise exceptions.missingReportInfoException()

        # Get the token if possible
        chatlog = ""
        token = glob.tokens.getTokenFromUsername(userUtils.safeUsername(target), safe=True)
        if token is not None:
            chatlog = token.getMessagesBufferString()

        # Everything is fine, submit report
        glob.db.execute(
            "INSERT INTO reports (id, from_uid, to_uid, reason, chatlog, time, assigned) VALUES (NULL, %s, %s, %s, %s, %s, 0)",
            [userUtils.getID(fro), targetID, "{reason} - ingame {info}".format(reason=reason, info="({})".format(
                additionalInfo) if additionalInfo is not None else ""), chatlog, int(time.time())])
        msg = "You've reported {target} for {reason}{info}. A Community Manager will check your report as soon as possible. Every !report message you may see in chat wasn't sent to anyone, so nobody in chat, but admins, know about your report. Thank you for reporting!".format(
            target=target, reason=reason, info="" if additionalInfo is None else " (" + additionalInfo + ")")
        adminMsg = "{user} has reported {target} for {reason} ({info})".format(user=fro, target=target, reason=reason,
                                                                               info=additionalInfo)

        # Log report in #admin and on discord
        chat.sendMessage(glob.BOT_NAME, "#admin", adminMsg)
        log.warning(adminMsg, discord="cm")
    except exceptions.invalidUserException:
        msg = "Hello, {} here! You can't report me. I won't forget what you've tried to do. Watch out.".format(
            glob.BOT_NAME)
    except exceptions.invalidArgumentsException:
        msg = "Invalid report command syntax. To report an user, click on it and select 'Report user'."
    except exceptions.userNotFoundException:
        msg = "The user you've tried to report doesn't exist."
    except exceptions.missingReportInfoException:
        msg = "Please specify the reason of your report."
    except:
        raise
    finally:
        if msg != "":
            token = glob.tokens.getTokenFromUsername(fro)
            if token is not None:
                if token.irc:
                    chat.sendMessage(glob.BOT_NAME, fro, msg)
                else:
                    token.enqueue(serverPackets.notification(msg))
    return False
Exemple #2
0
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)
Exemple #3
0
    def noticePrivmsgHandler(self, command, arguments):
        """NOTICE and PRIVMSG commands handler (same syntax)"""
        # Syntax check
        if len(arguments) == 0:
            self.replyCode(411, "No recipient given ({})".format(command))
            return
        if len(arguments) == 1:
            self.replyCode(412, "No text to send")
            return
        recipientIRC = arguments[0]
        message = arguments[1]

        # Send the message to bancho and reply
        if not recipientIRC.startswith("#"):
            recipientBancho = chat.fixUsernameForBancho(recipientIRC)
        else:
            recipientBancho = recipientIRC
        response = chat.sendMessage(self.banchoUsername,
                                    recipientBancho,
                                    message,
                                    toIRC=False)
        if response == 404:
            self.replyCode(404, "Cannot send to channel", channel=recipientIRC)
            return
        elif response == 403:
            self.replyCode(403, "No such channel", channel=recipientIRC)
            return
        elif response == 401:
            self.replyCode(401, "No such nick/channel", channel=recipientIRC)
            return

        # Send the message to IRC and bancho
        if recipientIRC.startswith("#"):
            # Public message (IRC)
            if recipientIRC not in glob.channels.channels:
                self.replyCode(401,
                               "No such nick/channel",
                               channel=recipientIRC)
                return
            for _, value in self.server.clients.items():
                if recipientIRC in value.joinedChannels and value != self:
                    value.message(":{} PRIVMSG {} :{}".format(
                        self.IRCUsername, recipientIRC, message))
        else:
            # Private message (IRC)
            for _, value in self.server.clients.items():
                if value.IRCUsername == recipientIRC:
                    value.message(":{} PRIVMSG {} :{}".format(
                        self.IRCUsername, recipientIRC, message))
Exemple #4
0
    def registerHandler(self, command, arguments):
        """NICK and USER commands handler"""
        if command == "NICK":
            if len(arguments) < 1:
                self.reply("431 :No nickname given")
                return
            nick = arguments[0]

            # Make sure this is the first time we set our nickname
            if self.IRCUsername != "":
                self.reply("432 * %s :Erroneous nickname" % nick)
                return

            # Make sure the IRC token was correct:
            # (self.supposedUsername is already fixed for IRC)
            if nick.lower() != self.supposedUsername.lower():
                self.reply("464 :Password incorrect")
                return

            # Make sure that the user is not banned/restricted:
            if not userUtils.isAllowed(self.supposedUserID):
                self.reply("465 :You're banned")
                return

            # Make sure we are not connected to Bancho
            token = glob.tokens.getTokenFromUsername(
                chat.fixUsernameForBancho(nick), True)
            if token is not None:
                self.reply("433 * {} :Nickname is already in use".format(nick))
                return

            # Everything seems fine, set username (nickname)
            self.IRCUsername = nick  # username for IRC
            self.banchoUsername = chat.fixUsernameForBancho(
                self.IRCUsername)  # username for bancho

            # Disconnect other IRC clients from the same user
            for _, value in self.server.clients.items():
                if value.IRCUsername.lower() == self.IRCUsername.lower(
                ) and value != self:
                    value.disconnect(quitmsg="Connected from another client")
                    return
        elif command == "USER":
            # Ignore USER command, we use nickname only
            return
        elif command == "QUIT":
            # Disconnect if we have received a QUIT command
            self.disconnect()
            return
        else:
            # Ignore any other command while logging in
            return

        # If we now have a valid username, connect to bancho and send IRC welcome stuff
        if self.IRCUsername != "":
            # Bancho connection
            chat.IRCConnect(self.banchoUsername)

            # IRC reply
            self.replyCode(1, "Welcome to the Internet Relay Network")
            self.replyCode(
                2, "Your host is {}, running version pep.py-{}".format(
                    self.server.host, glob.VERSION))
            self.replyCode(3, "This server was created since the beginning")
            self.replyCode(
                4, "{} pep.py-{} o o".format(self.server.host, glob.VERSION))
            self.sendLusers()
            self.sendMotd()
            self.__handleCommand = self.mainHandler