def get_membership_details(meeting_uuid: str, user_uuid: str): validate_meeting_uuid(meeting_uuid) validate_user_uuid(user_uuid) meeting = find_meeting(meeting_uuid) user = find_user(user_uuid) membership = find_membership(meeting_uuid, user_uuid) return { 'uuid': meeting.uuid, 'name': meeting.name, 'description': meeting.description, 'datetime': format_datetime(meeting.datetime), 'stop_name': meeting.stop_name, 'members': [{ 'nickname': membership.nickname, 'is_owner': is_owner(membership.user, meeting), 'is_you': membership.user == user, 'stop_name': membership.stop_name, } for membership in meeting.users], 'membership': { 'is_owner': is_owner(user, meeting), 'stop_name': membership.stop_name, } }, 200
def install(irc, event, args): """<plugin> Installs <plugin> if plugin is found online and is not already installed """ plugin_sources = check(irc) success = False if utils.is_owner(irc, event.source): try: if args[0] + ".py" not in os.listdir("plugins"): for plugin_source_url in irc.plugins[name]["urls"]: for plugin_name in irc.plugins[name]["urls"][plugin_source_url]: if args[0] + ".py" == plugin_name: try: deltax = requests.get(irc.plugins[name]["urls"][plugin_source_url][plugin_name]).text with open("plugins/" + args[0] + ".py", "w") as plugin_to_write: irc.reply(event, "Installing plugin: {}".format(args[0])) plugin_to_write.write(deltax) plugin_to_write.close() success = True irc.reply(event, "Plugin successfully installed") except: irc.reply(event, "The plugin couldn't be found online") elif args[0] + ".py" in os.listdir("plugins"): irc.reply(event, "That plugin is already installed") except KeyError: pass
def customcmd(cog, server_id): is_admin = utils.is_admin(server_id) owner = utils.session["user"]["id"] customcmd_content = db.hgetall("{}:Customcmd:content".format(server_id)) customcmd_brief = db.hgetall("{}:Customcmd:brief".format(server_id)) customcmd_owner = db.hgetall("{}:Customcmd:owner".format(server_id)) current_use = db.hget("{}:Customcmd:owner_use".format(server_id),owner) or 0 use = max_use(server_id) content = {} brief = {} if customcmd_content: customcmd_content = dict([x,str(y.encode()).replace("\\\\","\\")] for x,y in customcmd_content.items()) #a way to fix escape term. terrible yeh if is_admin or utils.is_owner(): #if someone is admin, they can view all log.info("It is admin person") member = db.hgetall("Info:Name") content = customcmd_content brief = customcmd_brief owner = {} for name,_id in customcmd_owner.items(): owner[name] = member.get(_id,"UNKNOWN") #getting member name WHILE checking left member else: log.info("Not admin person") for cmd in customcmd_content:#running check each commands to filter out to owner only if customcmd_owner[cmd] == owner: content[cmd] = customcmd_content[cmd] brief[cmd] = customcmd_brief[cmd] owner = "none" return render_template("customcmd.html", data_customcmd=content,data_brief = brief, server_id=server_id,max_use = use,current = current_use,cmd_owner = owner, cog = "customcmd")
def max_use(server_id): if utils.is_owner(): return 99 #well..... user = utils.session.get('user') role_data = db.hgetall("{}:Customcmd:role".format(server_id)) get_user_role = utils.resource_get("/guilds/{}/members/{}".format(server_id,user['id']))["roles"] use = [] for role,num in role_data.items(): if role in get_user_role: use.append(num) if use: max_cmd = max([int(x) for x in use]) else: max_cmd = 0 return max_cmd
def leave_meeting(user_uuid: str, meeting_uuid: str): validate_user_uuid(user_uuid) validate_meeting_uuid(meeting_uuid) meeting = find_meeting(meeting_uuid) user = find_user(user_uuid) if is_owner(user, meeting): raise ApiException('Meeting owner cannot leave meeting', 403) membership = find_membership(meeting_uuid, user_uuid) db.session.delete(membership) db.session.commit() return '', 204
def available(irc, event, args): """takes no arguments Checks for new plugins that can be installed. """ available_plugins = [] plugin_sources = check(irc) if utils.is_owner(irc, event.source): for plugin_source_url in irc.plugins[name]["urls"]: for plugin in irc.plugins[name]["urls"][plugin_source_url]: if plugin not in os.listdir("plugins"): available_plugins.append(plugin.replace("plugins/","").replace(".py", "")) if available_plugins: irc.reply(event, "The following plugin(s) can be installed: {}".format(" | ".join(available_plugins))) else: irc.reply(event, "You have all the plugins installed given the {} urls in this plugin: plugins.py".format(len(irc.plugins[name]["urls"])))
def updates(irc, event, args): """takes no arguments Checks for plugins that can be updated. """ plugin_sources = check(irc) updates = [] if utils.is_owner(irc, event.source): for plugin_source_url in irc.plugins[name]["urls"]: for plugin_name in irc.plugins[name]["urls"][plugin_source_url]: for active_plugin in os.listdir("plugins"): if active_plugin == plugin_name: with open("plugins/" + active_plugin, "r") as deltax: if deltax.read() != requests.get(irc.plugins[name]["urls"][plugin_source_url][plugin_name]).text: updates.append(active_plugin.replace(".py", "")) deltax.close() if updates: irc.reply(event, "The following plugin(s) can be updated: {}".format(" ".join(updates))) else: irc.reply(event, "No plugins can be updated")
def uninstall(irc, event, args, utils = utils): plugin_sources = check(irc) if utils.is_owner(irc, event.source): try: if utils.is_allowed(irc, event.source, event.target): for plugin_source_url in irc.plugins[name]["urls"]: for plugin in irc.plugins[name]["urls"][plugin_source_url]: if plugin in os.listdir("plugins") and args[0] == plugin.replace(".py", ""): try: irc.reply(event, "Uninstalling plugin") os.remove("plugins/" + plugin) irc.reply(event, "Plugin successfully uninstalled") except: irc.reply(event, "That plugin cannot be uninstalled") elif plugin not in os.listdir("plugins") and args[0] == plugin.replace(".py", ""): irc.reply(event, "That plugin isn't installed") else: pass except KeyError: pass
def update(irc, event, args): """<plugin> Updates <plugin> if an update is available. """ plugin_sources = check(irc) success = False if utils.is_owner(irc, event.source): try: if args[0] + ".py" in os.listdir("plugins"): for plugin_source_url in irc.plugins[name]["urls"]: for plugin_name in irc.plugins[name]["urls"][plugin_source_url]: if args[0] + ".py" == plugin_name: with open("plugins/" + args[0] + ".py", "r") as plugin_to_read: try: deltax = requests.get(irc.plugins[name]["urls"][plugin_source_url][plugin_name]).text except: irc.reply(event, "The plugin couldn't be found online") if plugin_to_read.read() != deltax: plugin_to_read.close() with open("plugins/" + args[0] + ".py", "w") as plugin_to_write: irc.reply(event, "Updating plugin: {}".format(args[0])) plugin_to_write.write(deltax) plugin_to_write.close() success = True irc.reply(event, "Plugin updated successfully") else: irc.reply(event, "That plugin is at its latest version") elif args[0] + ".py" not in os.listdir("plugins"): irc.reply(event, "That plugin isn't installed") if not success: irc.reply(event, "That plugin couldn't be installed") except KeyError: pass