示例#1
0
async def on_message(message):
    """Deal with incoming messages"""
    # Add new chats to the database
    if not DATABASE.is_known_chat(message.channel.id):
        DATABASE.add_chat_to_db(await get_chat_info(message))
    # Greet first time users
    if not message.guild and message.author != BOT.user and not message.channel.history(limit=1):
        await message.channel.send(None, embed=await start_message())
    else:
        await BOT.process_commands(message)
async def unsubscribe(ctx, *args):
    """unsubscribe from firmware/miui/vendor updates"""
    if not await subscription_allowed(ctx.message):
        return
    if len(args) > 2:
        return
    sub_type = args[0]
    if sub_type not in ["firmware", "miui", "vendor"]:
        return
    device = args[1]
    if not await is_device(sub_type, device):
        await ctx.send("**Wrong codename!**")
        return
    DATABASE.remove_subscription(await get_chat_info(ctx), sub_type, device)
    message = f"Unsubscribed from {device} {sub_type} updates successfully!"
    await ctx.send(None, embed=Embed(title=message))
示例#3
0
async def post_firmware_updates():
    """ Send firmware updates to subscribers every 65 minutes """
    while True:
        new_updates = await diff_updates(PROVIDER.firmware_data,
                                         PROVIDER.bak_firmware_data)
        if not new_updates:
            await sleep(65 * 60)
            continue
        for codename, updates in new_updates.items():
            subscriptions = DATABASE.get_subscriptions('firmware', codename)
            if subscriptions:
                for subscription in subscriptions:
                    for update in updates:
                        chat = BOT.get_user(subscription[0]) \
                            if subscription[1] == "user" else BOT.get_channel(subscription[0])
                        if not chat:
                            continue
                        await chat.send(
                            None,
                            embed=Embed(
                                title=
                                f"**New Firmware update available for {codename}**",
                                description=f"{update}",
                                url=f"{XFU_WEBSITE}/firmware/{codename}/"))
                        await sleep(2)
        await sleep(65 * 60)
示例#4
0
async def post_miui_updates():
    """ Send miui updates to subscribers every 65 minutes """
    while True:
        recovery_updates = await diff_miui_updates(
            PROVIDER.miui_recovery_updates, PROVIDER.bak_miui_recovery_updates)
        fastboot_updates = await diff_miui_updates(
            PROVIDER.miui_fastboot_updates, PROVIDER.bak_miui_fastboot_updates)
        for new_updates in [recovery_updates, fastboot_updates]:
            if not new_updates:
                await sleep(65 * 60)
                continue
            for codename, updates in new_updates.items():
                subscriptions = DATABASE.get_subscriptions('miui', codename)
                if subscriptions:
                    for subscription in subscriptions:
                        for update in updates:
                            embed = await miui_update_message(
                                update, PROVIDER.codenames_names)
                            chat = BOT.get_user(subscription[0]) \
                                if subscription[1] == "user" else BOT.get_channel(subscription[0])
                            if not chat:
                                continue
                            await chat.send(None, embed=embed)
                            await sleep(2)
            await sleep(65 * 60)
async def subscription_handler(ctx):
    """List your current subscriptions"""
    if not await subscription_allowed(ctx.message):
        return
    subscriptions = DATABASE.get_chat_subscriptions(ctx.message.channel.id)
    message = ""
    for subscription in subscriptions:
        message += f"{subscription[1]} ({subscription[0]})"
    embed = Embed(title=f"**You're subscribed to:**", description=message)
    await ctx.send(None, embed=embed)
async def subscribe(ctx, *args):
    """Subscribe to firmware/miui/vendor updates"""
    if len(args) > 2:
        return
    sub_type = args[0]
    if sub_type not in ["firmware", "miui", "vendor"]:
        return
    device = args[1]
    if not await is_device(sub_type, device):
        await ctx.send("**Wrong codename!**")
        return
    if not await subscription_allowed(ctx.message):
        return
    if DATABASE.add_subscription(await get_chat_info(ctx), sub_type, device):
        message = f"Subscribed to {device} {sub_type} updates successfully!"
    else:
        message = f"You are already subscribed to {device} {sub_type} updates!"
    await ctx.send(None, embed=Embed(title=message))
示例#7
0
async def stats_handler(ctx):
    if ctx.author.id in DISCORD_BOT_ADMINS:
        stats = DATABASE.get_stats()
        message = await stats_message(stats)
        await ctx.send(None, embed=Embed(title="Stats", description=message))