~nova/fletcher

ref: c1acd163f33f54a9b253f908f8387cb0c0a07fa7 fletcher/utils/histscr.py -rw-r--r-- 1.4 KiB
c1acd163 — Novalinium muple 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import configparser
import discord
import os
import sys

FLETCHER_CONFIG = os.getenv('FLETCHER_CONFIG', './.fletcherrc')

config = configparser.ConfigParser()
config.read(FLETCHER_CONFIG)

client = discord.Client()

# token from https://discordapp.com/developers
token = config['discord']['botToken']

@client.event
async def on_ready():
    argv = sys.argv
    if len(argv) > 1:
        argv[1] = int(argv[1])
    for guild in client.guilds:
        for channel in guild.text_channels:
            try:
                if len(argv) > 1 and guild.id != argv[1] and channel.id != argv[1]:
                    continue
                async for message in channel.history(limit=None):
                    print("{} {}:{} {} <{}>: {}".format(message.id, message.guild.name, message.channel.name, message.created_at, message.author.display_name, message.content))
                    for attachment in message.attachments:
                        print("{} Attachment: {}".format(message.id, attachment.url))
                    for reaction in message.reactions:
                        async for user in reaction.users():
                            print("{} from {}".format(str(reaction), str(user)))
            except discord.Forbidden as e:
                print("Not enough permissions to retrieve logs for {}:{}".format(guild.name, channel.name))
                pass
    await client.close()
client.run(token)