async def run_migration():
    config = Config.load()
    bot = DiscordBot(config)

    async with bot.connection():
        changeset = await bot.get_custom_emoji_changeset()
        logger.info("Replacing every emoji (this will take a while)...")

        await bot.apply_custom_emoji_changeset(changeset,
                                               update_action=REPLACE)
Ejemplo n.º 2
0
def steps(steps: List[Step], config: Config):
    for step in steps:
        logger.info(f"Running {fmt_step(step)}...")
        try:
            subprocess.run(
                [str(s) for s in step],
                check=True,
                cwd=PROJECT_ROOT,
                env=config.step_env,
            )
        except subprocess.CalledProcessError as exc:
            raise StepError(step, config.step_env) from exc
    logger.info("Cool beans!")
Ejemplo n.º 3
0
async def sync_emojis(config, yarly, dry_run, update_action):
    bot = DiscordBot(config)

    async with bot.connection():
        changeset = await bot.get_custom_emoji_changeset()

        click.echo(changeset.report(update_action=update_action))

        if dry_run:
            logger.info("Exiting after a dry run...")
        elif yarly or click.confirm("Do you want to apply these changes?"):
            await bot.apply_custom_emoji_changeset(changeset,
                                                   update_action=update_action)
        else:
            logger.warning("Not doing!")
Ejemplo n.º 4
0
    def diff(cls, upstream: List[EmojiResource],
             local: EmojiMapping) -> "Changeset":
        upstream_lookup: Dict[str, EmojiResource] = dict()
        upstream_keys: Set[str] = set()
        managed_keys: Set[str] = set()
        local_keys: Set[str] = set(local.keys())

        for up in upstream:
            upstream_lookup[up.name] = up
            if up.managed:
                managed_keys.add(up.name)
                logger.info(
                    f"Emoji {up.name} is managed, so leaving it alone...")
            else:
                upstream_keys.add(up.name)

        return cls(
            update=[(key, upstream_lookup[key], local[key])
                    for key in upstream_keys & local_keys],
            remove=[(key, upstream_lookup[key])
                    for key in upstream_keys - local_keys],
            create=[(key, local[key])
                    for key in local_keys - upstream_keys - managed_keys],
        )
Ejemplo n.º 5
0
 async def apply_custom_emoji_changeset(self,
                                        changeset: Changeset,
                                        update_action: UpdateAction = EDIT):
     for name, emoji in changeset.create:
         logger.info(f"Creating emoji {name}...")
         await self.create_custom_emoji(emoji,
                                        reason="Creating a fresh emoji!")
     for name, resource in changeset.remove:
         logger.info(f"Removing emoji {name}...")
         await self.delete_custom_emoji(resource.id)
     for name, resource, emoji in changeset.update:
         if update_action == REPLACE:
             logger.info(f"Individually replacing emoji {name}...")
             await self.replace_custom_emoji(
                 resource.id, emoji, reason="Issuing a blind replace!")
         else:
             logger.info(
                 f"I would edit emoji {name} if that were implemented...")
Ejemplo n.º 6
0
 async def wait_until_ready(self):
     await self.client.wait_until_ready()
     logger.info("The bot is ready!")
Ejemplo n.º 7
0
 async def close(self):
     logger.info("Closing the Discord bot websocket connection...")
     await self.client.close()
Ejemplo n.º 8
0
 async def start(self):
     logger.info("Starting the Discord bot...")
     await self.client.start(self.config.DISCORD_API_TOKEN)