Пример #1
0
async def addRule(ctx, *rule):
    rule = str(" ".join(rule[:]))
    filePath = ExtFuncs.filePath(gid)
    with open(filePath.jsonPath, "rt") as ruleDict:
        ruleDict = json.loads(ruleDict.read())
        minorRuleDict = ruleDict.get('TwitchChannel')
        subRuleDict = minorRuleDict.get('Rules')

    if (ctx.author.name.lower() == os.environ["CHANNEL"]
            or ctx.author.is_mod == True):
        writeRuleFile = open(filePath.jsonPath, 'wt')
        try:
            sortKeys = sorted(subRuleDict.keys())
            newKey = int(sortKeys[-1]) + 1
        except:
            newKey = 1
        subRuleDict.update({str(newKey): rule})
        minorRuleDict.update({'Rules': subRuleDict})
        ruleDict.update({'TwitchChannel': minorRuleDict})
        writeRuleFile.write(json.dumps(ruleDict, indent=2))
        writeRuleFile.close()
        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!")
Пример #2
0
async def removeRule(ctx, ruleNum):
    filePath = ExtFuncs.filePath(gid)
    ruleNum = str(ruleNum)
    with open(filePath.jsonPath, 'rt') as ruleDict:
        ruleDict = json.loads(ruleDict.read())
        minorRuleDict = ruleDict.get('TwitchChannel')
        subRuleDict = minorRuleDict.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)
            minorRuleDict.update({'Rules': subRuleDict})
            ruleDict.update({'TwitchChannel': minorRuleDict})
            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!")
Пример #3
0
async def rule(ctx, num):
    subRuleDict = ExtFuncs.filePath(gid).twitchData.get('Rules')

    if str(num).lower() in subRuleDict.keys():
        await ctx.send("/me " + subRuleDict.get(num))
    else:
        await ctx.send("/me That rule could not be found.")
Пример #4
0
async def event_filter(ctx):
    # A function to read every message and moderate based off of a predetermined list of words
    bannedWordsList = ExtFuncs.filePath(gid).bannedWords
    for listObj in bannedWordsList:
        listObjIndex = bannedWordsList.index(listObj)
        listObj = listObj.rstrip("\n")
        bannedWordsList[listObjIndex] = listObj
    userName = ctx.author.name
    print("Running filter")
    if (ctx.author.name.lower() == os.environ['BOT_NICK'].lower()
            or ctx.author.is_mod == True):
        print(
            "The message was sent by the channel owner, a moderator, or the bot, and thus was ignored by the filter."
        )
        return
    else:
        msgToList = ctx.content.split(" ")
        #        print(msgToList)
        for item in msgToList:
            itemFinal = ExtFuncs.puncStrip(item)
            if (str(itemFinal).lower() in bannedWordsList):
                await ctx.channel.send(
                    "@" + userName +
                    " Please refrain from using that language.")
                await ctx.channel.timeout(userName, 30,
                                          "Poor choice of words...")
            else:
                continue
Пример #5
0
 async def addAdminRole(self, ctx, roleToAdd=None):
     print(roleToAdd)
     print(type(roleToAdd))
     if roleToAdd != None:
         pass
     else:
         await ctx.send('No role specified.')
         return
     filePath = util.filePath(ctx.guild.id)
     with open(filePath.jsonPath, 'rt') as readVars:
         varData = json.loads(readVars.read())
         roles = varData.get('Roles')
         admins = roles.get('Admins')
     if isinstance(roleToAdd, discord.Role):
         roleToAdd = roleToAdd.id
     else:
         try:
             roleToAdd = int(roleToAdd)
         except:
             await ctx.send('Invalid role or role ID.')
             return
     admins.append(roleToAdd)
     roles.update({'Admins': admins})
     varData.update({'Roles': roles})
     with open(filePath.jsonPath, 'wt') as writeVars:
         writeVars.write(json.dumps(varData, indent=2))
     await ctx.send(f'Successfully added {ctx.guild.get_role(roleToAdd).mention} as an admin role.')
Пример #6
0
    async def amStrimmer(self, ctx, channelName=None):
        if channelName == None:
            await ctx.send('Please include a twitch channel name to check for live activity.')
        else:
            pass
        guildVarPath = util.filePath(ctx.guild.id)

        with open(pathlib.Path(f'Vars/globalVars.json'), 'rt') as readFile:
            existingData = json.loads(readFile.read())
            streamers = existingData.get('TwitchChannel')
            streamers.update({ctx.guild.id: channelName})
            existingData.update({'TwitchChannel': streamers})

        with open(pathlib.Path(f'Vars/globalVars.json'), 'wt') as writeFile:
            writeFile.write(json.dumps(existingData, indent=2))

        guildReadVars = guildVarPath.jsonData
        dcBackend = guildReadVars.get('DiscordBackend')
        dcBackend.update({'streamTTVChannel': channelName})
        guildReadVars.update({'DiscordBackend': dcBackend})
        
        try:
            twitchData = guildReadVars.get('TwitchChannel')
        except:
            twitchData = None
        if twitchData == None:
            twitchData = {'entryLines': [], 'missTxt': '', 'channelRules': {}, 'easterEggs': False}
        else:
            pass
        guildReadVars.update({'TwitchChannel': twitchData})

        with open(guildVarPath.jsonPath, 'wt') as guildWriteVarsFile:
            guildWriteVarsFile.write(json.dumps(guildReadVars, indent=2))
        await ctx.send(f'{ctx.guild.name} has been successfully added as a streaming server!')
Пример #7
0
async def rules(ctx):
    msg = "/me Here are the channel rules! "
    subRuleDict = ExtFuncs.filePath(gid).twitchData.get('Rules')

    if subRuleDict != None or subRuleDict != {}:
        for rule in sorted(subRuleDict.keys()):
            msg = msg + rule + ". " + str(subRuleDict.get(rule)) + " "
    else:
        msg = f'No rules could be found for the channel: {channelToJoin[0]}'
    await ctx.send(str(msg))
Пример #8
0
async def event_ready():
    global checker
    'Called once when the bot goes online.'
    print(f"{os.environ['BOT_NICK']} is now online!")
    await joinChannel(channelToJoin)
    await bot.part_channels(initChannels)
    varData = ExtFuncs.filePath(gid).twitchData
    try:
        randomEntrance = random.choice(varData.get('entryLines'))
    except:
        randomEntrance = f'No custom entrance lines for the bot were found. To add some, please use the command "!addEntry <text for bot to say when joining the chat>"'
    if ExtFuncs.filePath(gid).twitchData.get('EasterEggs'):
        bot.load_module('modules.twitchCogs.easterEggs')
    else:
        pass
    print(randomEntrance)
    checker = dataChecker(data)
    checker.check()
    ws = bot._ws
    await ws.send_privmsg(channelToJoin[0], f"/me {randomEntrance}")
Пример #9
0
async def updateMiss(ctx, *txt):
    if (ctx.author.is_mod == True):
        fileData = ExtFuncs.filePath(gid)
        msgData = fileData.jsonData
        twitchStuffs = msgData.get('TwitchChannel')
        twitchStuffs.update({'missTxt': (" ".join(txt[:]))})
        msgData.update({'TwitchChannel': twitchStuffs})
        with open(fileData.jsonPath, 'wt') as writeOut:
            writeOut.write(json.dumps(msgData, indent=2))
        await ctx.send("What did I miss file has been updated successfully.")
    else:
        await ctx.send(
            "You do not have the required permissions to use this command!")
Пример #10
0
async def disableEggs(ctx):
    channelData = ExtFuncs.filePath(gid)
    jsonData = channelData.jsonData
    twitchData = channelData.twitchData
    twitchData.update({'EasterEggs': False})
    jsonData.update({'TwitchChannel': twitchData})
    with open(channelData.jsonPath, 'wt') as writeData:
        writeData.write(json.dumps(jsonData, indent=2))
    await ctx.send('Easter eggs now disabled.')
    bot.unload_module('modules.twitchCogs.easterEggs')
    try:
        bot.unload_module('modules.twitchCogs.easterEggs')
        #await ctx.send('Easter eggs have been stopped successfully')
    except:
        #await ctx.send('Failed to unload the easter eggs. Consider restarting the twitch bot from discord by running ".killTwitch" followed by ".runTwitch"')
        pass
    return
Пример #11
0
async def enableEggs(ctx):
    channelData = ExtFuncs.filePath(gid)
    jsonData = channelData.jsonData
    twitchData = channelData.twitchData
    twitchData.update({'EasterEggs': True})
    jsonData.update({'TwitchChannel': twitchData})
    with open(channelData.jsonPath, 'wt') as writeData:
        writeData.write(json.dumps(jsonData, indent=2))
    await ctx.send('Easter eggs successfully enabled; Enjoy! :)')
    try:
        bot.load_module('modules.twitchCogs.easterEggs')
        await ctx.send('Easter eggs now running! :D')
    except:
        await ctx.send(
            'Failed to load the easter eggs. Consider restarting the twitch bot from discord by running ".killTwitch" followed by ".runTwitch"'
        )
    return
Пример #12
0
async def addEntry(ctx, *txt):
    if (ctx.author.is_mod == True):
        fileData = ExtFuncs.filePath(gid)
        msgData = fileData.jsonData
        twitchStuffs = msgData.get('TwitchChannel')
        entryLines = twitchStuffs.get('entryLines')
        newEntry = str(" ".join(txt[:]))
        print(entryLines)
        entryLines.append(newEntry)
        twitchStuffs.update({'entryLines': entryLines})
        msgData.update({'TwitchChannel': twitchStuffs})
        with open(fileData.jsonPath, 'wt') as writeOut:
            writeOut.write(json.dumps(msgData, indent=2))
        await ctx.send(f"The entry {newEntry} was successfully added.")
    else:
        await ctx.send(
            "You do not have the required permissions to use this command!")
Пример #13
0
    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.')
Пример #14
0
 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')
Пример #15
0
async def whatimiss(ctx):
    msg = ExtFuncs.filePath(gid).twitchData.get('missTxt')
    await ctx.send("@" + ctx.author.name + " While you were gone, " + msg)