async def removeRule(ctx, ruleNum): filePath = ExtFuncs.filePath(gid) with open(filePath.jsonPath, 'rt') as ruleDict: ruleDict = ruleDict subRuleDict = ruleDict.get('rules') if (ctx.author.name.lower() == os.environ["CHANNEL"] or ctx.author.is_mod == True): if (ruleNum in subRuleDict.keys()): writeRuleFile = open(filePath.jsonPath, "wt") subRuleDict.pop(ruleNum) ruleDict.update({'rules': subRuleDict}) writeRuleFile.write(json.dumps(ruleDict, indent=2)) await ctx.send("The rule with ID " + ruleNum + " has been successfully removed.") writeRuleFile.close() else: await ctx.send(f'The rule {str(ruleNum)} could not be found in the rule list.') else: await ctx.send("@" + ctx.author.name + " You don't have the permissions to use this command!")
async def addRule(ctx, *rule): rule = str(" ".join(rule[:])) filePath = ExtFuncs.filePath(gid) with open(filePath.jsonPath, "rt") as ruleDict: ruleDict = ruleDict subRuleDict = ruleDict.get('rules') writeRuleFile = open(filePath.jsonPath, 'wt') if (ctx.author.name.lower() == os.environ["CHANNEL"] or ctx.author.is_mod == True): sortKeys = sorted(subRuleDict.keys()) try: newKey = int(sortKeys[-1]) + 1 except: newKey = 1 subRuleDict.update({str(newKey): rule}) ruleDict.update({'rules': subRuleDict}) writeRuleFile.write(json.dumps(ruleDict, indent=2)) await ctx.send("The rule, " + '"' + str(rule) + '"' + " with the ID of " + str(newKey) + " has been successfully added to the rules list.") else: await ctx.send("@" + ctx.author.name + " You don't have the permissions to use this command!") writeRuleFile.close()
async def setStreamAnnounceChannel(self, ctx, channelId=None): filePath = util.filePath(ctx.guild.id) dcBackend = None with open(filePath.jsonPath, 'rt') as readGuildVarsFile: readGuildVars = json.loads(readGuildVarsFile.read()) dcBackend = readGuildVars.get('DiscordBackend') print(type(channelId)) if channelId == None: channelId = int(ctx.channel.id) # elif isinstance(channelId, str): # try: # channelId = ctx.guildchannelId.id else: try: channelId = int(channelId) except: await ctx.send('Invalid channel or channel ID.') return dcBackend.update({"streamAnnouncementChannel": channelId}) readGuildVars.update({'DiscordBackend': dcBackend}) with open(filePath.jsonPath, 'wt') as writeVarsFile: writeVarsFile.write(json.dumps(readGuildVars, indent=2)) await ctx.send(f'Successfully set {ctx.guild.get_channel(channelId).mention} as the stream announcement channel.')
def getChannel(self): getGlob = util.globalVars() return getGlob.streamers.get(str(self.guildId))
async def event_message_log(ctx): if ctx.guild != None: logPath = pathlib.Path(varPath / str(ctx.guild.id) / 'logs') else: logPath = pathlib.Path('logs/Discord') ExtFuncs.log(logPath, logNameVar, ctx.author, ctx.channel, ctx.content)
def __init__(self, gid): self.gid = gid self.varFile = ExtFuncs.filePath(gid) self.twitchData = self.varFile.twitchData self.guildData = self.varFile.jsonData self.customComs = self.varFile.twitchData.get('CustomComs')
async def whatimiss(ctx): msg = ExtFuncs.filePath(gid).twitchData.get('missTxt') await ctx.send("@" + ctx.author.name + " While you were gone, " + msg)