This repository was archived by the owner on Oct 4, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexisting_logger.py
More file actions
56 lines (43 loc) · 1.9 KB
/
existing_logger.py
File metadata and controls
56 lines (43 loc) · 1.9 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import logging
import logging.config
import discord
logging.basicConfig(level=logging.INFO)
logging.config.dictConfig({'version': 1, 'disable_existing_loggers': True})
LOGGER = logging.getLogger(__name__)
import yaml
from discord.ext import commands
import click
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
import db
from logger_modules.existing_log import ExistingArchiveHandler
from logger_modules.existing_db_ops import ExistingDatabaseOperations
import logger_modules.init_funcs
@click.command()
@click.argument("ID", type=int)
@click.option("--log-type", required=True, type=click.Choice(['guild', 'dm', 'channel']), help="Type of object you are trying to archive.")
def main(id, log_type):
"""Log existing messages from the source ID to the database.
Type must be passed in and indicates what you are trying to archive.
Logging guild will also update the member list of that guild with any unlogged users."""
with open("config.yml", "r") as configfile:
config = yaml.safe_load(configfile)
logger_modules.init_funcs.make_static_dirs(config)
engine = create_engine(config["database_url"], pool_size=30)
LOGGER.info("Connected to database.")
db.Base.metadata.bind = engine
session_factory = sessionmaker(engine)
DBSession = scoped_session(session_factory)
db_ops = ExistingDatabaseOperations(config, DBSession)
client = discord.Client()
handler = ExistingArchiveHandler(client, config, db_ops)
LOGGER.info("[%s][%s] Creating asyncio task", log_type, id)
if log_type == 'guild':
client.loop.create_task(handler.archive_guild(id))
elif log_type == 'dm':
client.loop.create_task(handler.archive_dm(id))
elif log_type == 'channel':
client.loop.create_task(handler.archive_channel(id))
client.run(config["token"], bot=config["bot"])
if __name__ == "__main__":
main()