Esempio n. 1
0
async def add_forbidden_word(ctx, *arg):
    forbidden_word = " ".join(arg)

    con = mysql.connector.connect(**con_info)
    insert(con, "forbidden_words", ["forbidden_word_id"], [forbidden_word])
    insert(con, "users", ["user_id"], [ctx.message.author.id])
    existance = does_exist(con, "forbidden_words_users",
                           ["forbidden_word_id", "user_id"],
                           [forbidden_word, ctx.message.author.id])

    if not existance:
        forbidden_words_users_id = insert(
            con, "forbidden_words_users", ["forbidden_word_id", "user_id"],
            [forbidden_word, ctx.message.author.id])

        if forbidden_words_users_id != -1:
            await ctx.send(
                f"Hewwo! I added **{forbidden_word}** to your Forbidden Words!"
            )
        else:
            await ctx.send(
                f"Oh nyo! I couldn't add **{forbidden_word}** to your Forbidden Words"
            )
    else:
        await ctx.send(
            f"Baka! **{forbidden_word}** is already in your Forbidden Words!")

    con.close()
Esempio n. 2
0
async def on_ready():
    channel = client.get_channel(CHANNEL_ID)
    logging.info(f'{str(datetime.datetime.now())}: Bot is ready')

    while True:
        logging.info(
            f'{str(datetime.datetime.now())}: Checking for new submissions: ')

        con = psycopg2.connect(DATABASE_URL, sslmode='require')

        all_subreddits = '+'.join([d[1] for d in query_all(con, 'subreddit')])
        all_keywords = [d[1] for d in query_all(con, 'keyword')]
        all_forbidden_words = [d[1] for d in query_all(con, 'forbidden_word')]

        logging.info(
            f'{str(datetime.datetime.now())}: Subreddits: {all_subreddits}')
        logging.info(
            f'{str(datetime.datetime.now())}: Keywords: {all_keywords}')
        logging.info(
            f'{str(datetime.datetime.now())}: Forbidden Words: {all_forbidden_words}'
        )
        logging.info(f'{str(datetime.datetime.now())}: Begin scraping')

        submissions = get_scraped_submissions(all_subreddits, all_keywords,
                                              all_forbidden_words)

        for submission in submissions:
            submission_does_exist = does_exist(con, 'submission', 'id',
                                               submission.id)

            if not submission_does_exist:
                logging.info(
                    f'{str(datetime.datetime.now())}: Found new submission: {submission.title[:100]}'
                )
                insert(
                    con, 'submission', ['id', 'title'],
                    [submission.id, submission.title[:100].replace("'", "")])
                await channel.send(
                    f'```{submission.title}```\n @everyone \n\n{submission.url}'
                )

        logging.info(f'{str(datetime.datetime.now())}: Finished scraping')

        # # Close the connection and sleep for 1 minute
        con.close()
        await asyncio.sleep(60)
Esempio n. 3
0
async def on_ready():
    bot_testing_channel = client.get_channel(BOT_TESTING_CHANNEL_ID)
    mechmarket_channel = client.get_channel(MECH_MARKET_CHANNEL_ID)
    keeb_updates_channel = client.get_channel(KEEB_UPDATES_CHANNEL_ID)
    artisans_update_channel = client.get_channel(ARTISAN_UPDATES_CHANNEL_ID)

    subreddits = ["MechMarket", "MechGroupBuys", "MechanicalKeyboards"]
    announcement_keywords = [
        "[gb]", "[ic]", "[IN STOCK]", "[PRE-ORDER]", "Novelkeys Updates"
    ]

    logging.info(f'{str(datetime.datetime.now())}: Bot is ready')
    await bot_testing_channel.send("MAZ Chan is ready! uWu")

    while True:
        con = mysql.connector.connect(**con_info)

        keywords = query_keywords()

        logging.info(
            f'{str(datetime.datetime.now())}: Checking for new submissions: ')
        submissions = get_scraped_submissions("+".join(subreddits))

        for submission in submissions:
            post_does_exist = does_exist(con, "mechmarket_posts", ["post_id"],
                                         [submission.id])

            if not post_does_exist:
                logging.info(
                    f'{str(datetime.datetime.now())}: Found new submission: {submission.title[:20]}'
                )
                insert(con, "mechmarket_posts", ["post_id", "title"],
                       [submission.id, submission.title[:100]])

                if any(announcement_keyword.lower() in
                       submission.title.lower()
                       for announcement_keyword in announcement_keywords):
                    await keeb_updates_channel.send(
                        f'```{submission.title}```\n \nhttps://redd.it/{submission.id}'
                    )

                if "[Artisan]" in submission.title:
                    await artisans_update_channel.send(
                        f'```{submission.title}```\n \nhttps://redd.it/{submission.id}'
                    )

                if submission.subreddit == "MechMarket":
                    matching_keywords = list(
                        filter(
                            lambda keyword: keyword.lower() in submission.title
                            .lower(), keywords))
                    mentions = set()

                    for matching_keyword in matching_keywords:
                        users = query_users_by_keywords(matching_keyword)

                        for uid in users:
                            forbidden_words = query_forbidden_words_by_user_id(
                                uid)

                            if not any(forbidden_word.lower() in
                                       submission.title.lower()
                                       for forbidden_word in forbidden_words):
                                mentions.add(client.get_user(uid).mention)

                    embed = discord.Embed()
                    embed.title = submission.title
                    embed.url = f"https://redd.it/{submission.id}"
                    image_url = get_url_at(0, submission.selftext_html)

                    if mentions:
                        await mechmarket_channel.send(
                            f'{", ".join(list(set(mentions)))}')
                    await mechmarket_channel.send(embed=embed)
                    if image_url:
                        await mechmarket_channel.send(image_url)

        logging.info(f'{str(datetime.datetime.now())}: Finished scraping')
        con.close()
        await asyncio.sleep(60)