Example #1
0
File: img.py Project: cxr00/Zote
 def r(self, tag):
     if len(self.current[tag]) == 0:
         self.current[tag] = Qoid(tag, copy.deepcopy(self[tag].val))
         self.current[tag].remove("tagged")
     elif len(self.current[tag]) == 1:
         next_img = self.current[tag].pop(0).val
         return next_img
     selection = randint(0, len(self.current[tag]) - 1)
     next_img = self.current[tag].pop(selection)
     return next_img.val
Example #2
0
File: bot.py Project: cxr00/Zote
 async def cog_create(ctx, *args):
     nonlocal cogs
     cog_name = args[0]
     if cog_name not in cogs:
         cogs += Qoid(cog_name)
         cogs.save(echo=False)
         await zote.say("Done")
     else:
         await zote.say("Already exists")
     pass
Example #3
0
File: bot.py Project: cxr00/Zote
 def record_msg(m: Message):
     if not m.server:
         return
     nonlocal che
     if m.server.id:
         if m.channel.id:
             if m.channel.id in che:
                 if m.id not in che[m.channel.id]:
                     che[m.channel.id] += Property(m.id)
             else:
                 che += Qoid(tag=m.channel.id)
                 che[m.channel.id] += Property(m.id)
             che.save(echo=False)
Example #4
0
File: disco.py Project: cxr00/Zote
def qoidify_server_channels(zote, s_id: str, tag=None):
    server = zote.get_server(s_id)
    out = Qoid(tag=tag if tag else server.name)
    for ch in server.channels:
        out += Property(ch.name, ch)
    return out
Example #5
0
async def grabulate(ctx, *args):

    # Step 1: Get channels
    channels = [e for e in args if isinstance(e, Channel)]
    ids = []
    delete = []
    for e in channels:
        if e.id not in ids:
            ids.append(e.id)
        else:
            delete.append(e)
    ids = []
    for e in delete:
        channels.remove(e)
    print([e.id for e in channels])

    if not channels:
        channels = [ctx.message.channel.id]

    for ch in channels:
        # Step 2: Guarantee presence in config file
        if ch.id not in cfg:
            cfg.append(Qoid(ch.id, cfg["template"].val))
            cfg[ch.id]["server"] = ch.server.name
            cfg[ch.id]["name"] = ch.name
            cfg.save()

        # Step 3: Ensure directory exists
        server = grab.get_server(ch.server.id)
        root = f"{cfg['init']['root']}\\{server.name} ({server.id})"
        ch_folder = f"{ch.name} ({ch.id})"
        if not os.path.isdir(f"{root}\\{ch_folder}"):
            try:
                if not os.path.isdir(root):
                    os.mkdir(root)
                os.mkdir(f"{root}\\{ch_folder}")
                loc = f"{root}\\{ch_folder}"
            except FileExistsError:
                if not os.path.isdir(root):
                    os.mkdir(f"{root}")
                os.mkdir(f"{root}_discord_downloads\\{ch_folder}")
                loc = f"{root}\\{ch_folder}_discord_downloads"
        else:
            loc = f"{root}\\{ch_folder}"

        print(f"Beginning save in {root}")

        # Step 3: Establish start and end points for logs_from
        bf = None
        new_bookmark = None
        async for msg in grab.logs_from(channel=ch, limit=1):
            bf = new_bookmark = msg.id
            if cfg[ch.id]["failsafe"]:
                bf = cfg[ch.id]["failsafe"]
        if cfg[ch.id]["bookmark"]:
            af = await grab.get_message(channel=ch, id=cfg[ch.id]["bookmark"])
        else:
            af = None

        # Step 4: Traverse logs for
        print("Searching for image attachments...")
        end = False
        while not end:
            prev = bf
            async for msg in grab.logs_from(channel=ch,
                                            limit=100,
                                            before=bf,
                                            after=af):
                if msg.author.id != cfg["init"]["bot"]:
                    await scrape_img(msg, loc)
                bf = msg
            if prev == bf:
                end = True
        cfg[ch.id]["bookmark"] = new_bookmark
        cfg[ch.id]["failsafe"] = None
        cfg.save(echo=False)
        print(f"Bookmark set to {new_bookmark}")
    print(f"Downloading from {len(channels)} complete.")
Example #6
0
from qoid import Property, Qoid, Bill

p_a = Property("PropertyA", "valueA")
p_b = Property("PropertyB", "valueB")
p_c = Property("PropertyC")

q_a = Qoid("Qoid A", [p_a, p_b])
q_b = Qoid("Qoid B", [p_b])
q_c = Qoid("Qoid C", [p_b, p_c])

b_a = Bill("Example Bill", [q_a, q_b, q_c])

b_a -= q_b

b_a.save()

b_a += q_b

print(b_a)

b_a = Bill.open("Example Bill.cxr")

print(b_a)