def load_commands(self, **options): if self.settings["mod_role_id"]: self.commands["modpride"] = Command.raw_command( self.modpride, command="modpride", delay_all=0, delay_user=0, cost=self.settings["cost_mod_pride"], can_execute_with_whisper=False, description="KappaPride Mods", ) if self.settings["dank_role_id"]: self.commands["dank"] = Command.raw_command( self.dank, command="dank", delay_all=self.settings["dank_cooldown"], delay_user=self.settings["dank_cooldown"], cost=self.settings["cost_dank"], can_execute_with_whisper=False, description="Messes with the dank roles color", ) self.commands["vroom"] = Command.raw_command( self.vroom, command="vroom", delay_all=0, delay_user=0, can_execute_with_whisper=False, description="VROOOOOOOOOOM", )
def load_commands(self, **options): self.commands["message"] = Command.raw_command( self.querymessage, level=int(self.settings["level_to_query"]), can_execute_with_whisper=True, description="Queries a message", )
def load_commands(self, **options): self.commands["movienight"] = Command.raw_command( self.movienight, delay_all=0, delay_user=0, can_execute_with_whisper=False, channels=json.dumps(self.settings["valid_channels"].split(" ")), description="Shows thge movienight links", ) self.commands["moviestart"] = Command.multiaction_command( delay_all=0, delay_user=0, default=None, can_execute_with_whisper=False, level=self.settings["level"], command="moviestart", commands={ "ull": Command.raw_command( self.moviestart_ull, command="moviestart ull", delay_all=0, delay_user=0, level=self.settings["level"], can_execute_with_whisper=False, channels=json.dumps(self.settings["valid_channels"].split(" ")), description="Creates an ultra-low-latency target (lowest latency, source quality only)", ), "cdn": Command.raw_command( self.moviestart_cdn, command="moviestart cdn", delay_all=0, delay_user=0, level=self.settings["level"], can_execute_with_whisper=False, channels=json.dumps(self.settings["valid_channels"].split(" ")), description="Starts a normal cdn target with transcoder (higher latency, adaptive bitrate)", ), }, ) if not self.bot: return if not self.bot.movienight_api.active: log.error("API is not running!") return
def load_commands(self, **options): self.commands["remindme"] = Command.raw_command( self.create_reminder, command="remindme", delay_all=0, delay_user=0, cost=int(self.settings["cost"]), can_execute_with_whisper=False, description="Creates a reminder", ) self.commands["forgetme"] = Command.raw_command( self.forgetme, command="forgetme", delay_all=0, delay_user=0, can_execute_with_whisper=False, description="Creates a reminder", )
def load_commands(self, **options): self.commands["module"] = Command.raw_command( self.cmd_module, level=500, description="Modify module", delay_all=0, delay_user=0, can_execute_with_whisper=True, )
def load_commands(self, **options): self.commands["addrolelevel"] = Command.raw_command( self.add_role_level, command="addrolelevel", delay_all=0, delay_user=0, level=int(self.settings["level"]), can_execute_with_whisper=True, description="Adds Level to role", ) self.commands["removerolelevel"] = Command.raw_command( self.remove_role_level, command="removerolelevel", delay_all=0, delay_user=0, level=int(self.settings["level"]), can_execute_with_whisper=True, description="Removes Level from role", )
def load_commands(self, **options): self.commands["chatchart"] = Command.raw_command( self.chatchart, command="chatchart", delay_all=0, delay_user=0, can_execute_with_whisper=False, description= "Generates a pie chart, representing messages in the specified channel.", )
def create_command(self, alias_str, **options): aliases = alias_str.lower().replace("!", "").split("|") for alias in aliases: if alias in self.data: return self.data[alias], False, alias command = Command(command=alias_str, **options) command.data = CommandData(command.id, **options) self.add_db_command_aliases(command) with DBManager.create_session_scope( expire_on_commit=False) as db_session: db_session.add(command) db_session.add(command.data) db_session.commit() db_session.expunge(command) db_session.expunge(command.data) self.db_session.add(command.data) self.commit() self.rebuild() return command, True, ""
def load_commands(self, **options): self.commands["timeout"] = Command.raw_command( self.timeout_user, command="timeout", delay_all=0, delay_user=0, level=int(self.settings["level_for_command"]), can_execute_with_whisper=False, description="Adds a timeout to a user", ) self.commands["untimeout"] = Command.raw_command( self.untimeout_user, command="untimeout", delay_all=0, delay_user=0, level=int(self.settings["level_for_command"]), can_execute_with_whisper=False, description="Removes a timeout on a user", ) self.commands["timeouts"] = Command.raw_command( self.query_timeouts, command="timeouts", delay_all=0, delay_user=0, level=int(self.settings["level_for_command"]), can_execute_with_whisper=False, description="Queries timeouts of a user", ) self.commands["istimedout"] = Command.raw_command( self.is_timedout, command="istimedout", delay_all=0, delay_user=0, level=int(self.settings["level_for_command"]), can_execute_with_whisper=False, description="Checks if the user is currently timedout", )
def __init__(self, args, default=None, fallback=None): from greenbot.models.command import Command self.commands = {} self.default = default self.fallback = fallback for command in args: cmd = Command.from_json(command) for alias in command["command"].split("|"): if alias not in self.commands: self.commands[alias] = cmd else: log.error(f"Alias {alias} for this multiaction is already in use.") import copy self.original_commands = copy.copy(self.commands)
def commands_create(**options): session.pop("command_created_id", None) session.pop("command_edited_id", None) if request.method != "POST": return render_template("admin/create_command.html") if "aliases" not in request.form: abort(403) alias_str = request.form.get("aliases", "").replace("!", "").lower() delay_all = request.form.get("cd", Command.DEFAULT_CD_ALL) delay_user = request.form.get("usercd", Command.DEFAULT_CD_USER) level = request.form.get("level", Command.DEFAULT_LEVEL) cost = request.form.get("cost", 0) try: delay_all = int(delay_all) delay_user = int(delay_user) level = int(level) cost = int(cost) except ValueError: abort(403) if not alias_str: abort(403) if delay_all < 0 or delay_all > 9999: abort(403) if delay_user < 0 or delay_user > 9999: abort(403) if level < 0 or level > 2000: abort(403) if cost < 0 or cost > 9999999: abort(403) user = options.get("user", None) if user is None: abort(403) options = { "delay_all": delay_all, "delay_user": delay_user, "level": level, "cost": cost, "added_by": user.discord_id, } valid_action_types = ["reply", "privatemessage"] action_type = request.form.get("type").lower() if action_type not in valid_action_types: abort(403) response = request.form.get("response", "") log.info(user.level) functions = ( request.form.get("functions", "").split(" ") if user.level >= 1500 else [] ) log.info(functions) action = {"type": action_type, "message": response, "functions": functions} options["action"] = action command_manager = greenbot.managers.command.CommandManager( socket_manager=None, module_manager=ModuleManager(None).load(), bot=None ).load(enabled=None) command_aliases = [] for alias, command in command_manager.items(): command_aliases.append(alias) if command.command and len(command.command) > 0: command_aliases.extend(command.command.split("|")) command_aliases = set(command_aliases) alias_str = alias_str.replace(" ", "").replace("!", "").lower() alias_list = alias_str.split("|") alias_list = [alias for alias in alias_list if len(alias) > 0] if not alias_list: return render_template("admin/create_command_fail.html") for alias in alias_list: if alias in command_aliases: return render_template("admin/create_command_fail.html") alias_str = "|".join(alias_list) command = Command(command=alias_str, **options) command.data = CommandData(command.id, **options) log_msg = f"The !{command.command.split('|')[0]} command has been created" AdminLogManager.add_entry("Command created", user.discord_id, log_msg) with DBManager.create_session_scope(expire_on_commit=False) as db_session: db_session.add(command) db_session.add(command.data) db_session.commit() db_session.expunge(command) db_session.expunge(command.data) SocketClientManager.send("command.update", {"command_id": command.id}) session["command_created_id"] = command.id return redirect("/admin/commands/", 303)
def load_internal_commands(self): if self.internal_commands: return self.internal_commands self.internal_commands = {} self.internal_commands["quit"] = Command.greenbot_command( self.bot, "quit", level=500, command="quit", description= "Shut down the bot, this will most definitely restart it if set up properly", can_execute_with_whisper=True, ) self.internal_commands["add"] = Command.multiaction_command( level=100, delay_all=0, delay_user=0, default=None, command="add", commands={ "command": Command.dispatch_command( "add_command", level=500, description="Add a command!", ), "alias": Command.dispatch_command( "add_alias", level=500, description="Adds an alias to an already existing command", ), "funccommand": Command.dispatch_command( "add_funccommand", level=1500, description="Add a command that uses a command", ), }, can_execute_with_whisper=True, ) self.internal_commands["edit"] = Command.multiaction_command( level=100, delay_all=0, delay_user=0, default=None, command="edit", commands={ "command": Command.dispatch_command( "edit_command", level=500, description="Edit an already-existing command", ), "funccommand": Command.dispatch_command( "edit_funccommand", level=1500, description="Add a command that uses a command", ), }, can_execute_with_whisper=True, ) self.internal_commands["remove"] = Command.multiaction_command( level=100, delay_all=0, delay_user=0, default=None, command="remove", commands={ "command": Command.dispatch_command( "remove_command", level=500, description="Remove a command!", ), "alias": Command.dispatch_command( "remove_alias", level=500, description= "Removes an alias to an already existing command", ), }, can_execute_with_whisper=True, ) self.internal_commands["rem"] = self.internal_commands["remove"] self.internal_commands["del"] = self.internal_commands["remove"] self.internal_commands["delete"] = self.internal_commands["remove"] return self.internal_commands
def load_commands(self, **options): self.commands["add"] = Command.multiaction_command( level=100, delay_all=0, delay_user=0, default=None, command="add", commands={ "link": Command.multiaction_command( command="add link", level=500, delay_all=0, delay_user=0, default=None, commands={ "blacklist": Command.raw_command( self.add_link_blacklist, command="add link blacklist", level=500, delay_all=0, delay_user=0, description="Blacklist a link", examples=[ CommandExample( None, "Add a link to the blacklist for a shallow search", chat="user:!add link blacklist --shallow scamlink.lonk/\n" "bot>user:Successfully added your links", description="Added the link scamlink.lonk/ to the blacklist for a shallow search", ).parse(), CommandExample( None, "Add a link to the blacklist for a deep search", chat="user:!add link blacklist --deep scamlink.lonk/\n" "bot>user:Successfully added your links", description="Added the link scamlink.lonk/ to the blacklist for a deep search", ).parse(), ], ), "whitelist": Command.raw_command( self.add_link_whitelist, command="add link whitelist", level=500, delay_all=0, delay_user=0, description="Whitelist a link", examples=[ CommandExample( None, "Add a link to the whitelist", chat="user:!add link whitelink safelink.lonk/\n" "bot>user:Successfully added your links", description="Added the link safelink.lonk/ to the whitelist", ).parse() ], ), }, ) }, ) self.commands["remove"] = Command.multiaction_command( level=100, delay_all=0, delay_user=0, default=None, command="remove", commands={ "link": Command.multiaction_command( command="remove link", level=500, delay_all=0, delay_user=0, default=None, commands={ "blacklist": Command.raw_command( self.remove_link_blacklist, command="remove link blacklist", level=500, delay_all=0, delay_user=0, description="Remove a link from the blacklist.", examples=[ CommandExample( None, "Remove a link from the blacklist.", chat="user:!remove link blacklist 20\n" "bot>user:Successfully removed blacklisted link with id 20", description="Remove a link from the blacklist with an ID", ).parse() ], ), "whitelist": Command.raw_command( self.remove_link_whitelist, command="remove link whitelist", level=500, delay_all=0, delay_user=0, description="Remove a link from the whitelist.", examples=[ CommandExample( None, "Remove a link from the whitelist.", chat="user:!remove link whitelist 12\n" "bot>user:Successfully removed blacklisted link with id 12", description="Remove a link from the whitelist with an ID", ).parse() ], ), }, ) }, )
def load_commands(self, **options): self.commands["giveaway"] = Command.multiaction_command( delay_all=0, delay_user=0, default="join", can_execute_with_whisper=False, command="giveaway", commands={ "join": Command.raw_command( self.giveaway_join, command="giveaway join", delay_all=0, delay_user=0, channels=json.dumps( self.settings["valid_channels"].split(" ")), can_execute_with_whisper=False, description="Joins the current giveaway", ), "info": Command.raw_command( self.giveaway_info, command="giveaway info", delay_all=0, delay_user=0, channels=json.dumps( self.settings["valid_channels"].split(" ")), can_execute_with_whisper=False, description="Info about the current giveaway", ) }, ) self.commands["startgiveaway"] = Command.raw_command( self.giveaway_start, command="startgiveaway", delay_all=0, delay_user=0, level=self.settings["level"], channels=json.dumps(self.settings["valid_channels"].split(" ")), can_execute_with_whisper=False, description="Start a giveaway", ) self.commands["wipegiveaway"] = Command.raw_command( self.giveaway_wipe, command="wipegiveaway", delay_all=0, delay_user=0, level=self.settings["level"], channels=json.dumps(self.settings["valid_channels"].split(" ")), can_execute_with_whisper=False, description="Clears the current giveaway", ) self.commands["giveawaywinner"] = Command.raw_command( self.giveaway_winner, command="giveawaywinner", delay_all=0, delay_user=0, level=self.settings["level"], channels=json.dumps(self.settings["valid_channels"].split(" ")), can_execute_with_whisper=False, description="Chooses a winner(s) for the current giveaway", ) self.commands["lockgiveaway"] = Command.raw_command( self.giveaway_lock, command="lockgiveaway", delay_all=0, delay_user=0, level=self.settings["level"], channels=json.dumps(self.settings["valid_channels"].split(" ")), can_execute_with_whisper=False, description="Locks the current giveaway", ) self.commands["unlockgiveaway"] = Command.raw_command( self.giveaway_unlock, command="unlockgiveaway", delay_all=0, delay_user=0, level=self.settings["level"], channels=json.dumps(self.settings["valid_channels"].split(" ")), can_execute_with_whisper=False, description="Unlocks the current giveaway", )