Example #1
0
async def tweetReminder(ctx, member: discord.Member = None):
    if (Config.usingTwitterBot):
        if member is None:
            member = ctx.message.author

        if "moderator" in [y.name.lower() for y in member.roles
                           ]:  # Check if the user is a moderator
            offset = datetime.datetime.utcnow() - server.getLastTweet(
            )  # Get the time since last tweet

            if (
                    offset.total_seconds() >= Config.twitter_timeSinceTweet
            ):  # Has **Config.twitter_timeSinceTweet** passed since the last tweet?
                timeDiff = JamInfo.getTimeDiff()  # Get the time remaining
                timeLeft = ""

                if (
                        timeDiff < 0
                ):  # If timeDiff is negative the jam has already started -- Too late to tweet
                    await bot.say("The jam has already started -- NOT TWEETING"
                                  )

                formattedDiff = JamInfo.formatTime(
                    timeDiff)  # Get the formatted array

                if (formattedDiff[0] != ""):
                    timeLeft = formattedDiff[0] + " " + formattedDiff[
                        1] + " " + formattedDiff[2]  # Day + Hour + Min
                elif (formattedDiff[1] != ""):
                    timeLeft = formattedDiff[1] + " " + formattedDiff[
                        2]  # Hour + Min
                elif (formattedDiff[2] != ""):
                    timeLeft = formattedDiff[2] + " " + formattedDiff[
                        3]  # Min + Sec
                else:
                    timeLeft = formattedDiff[3]  # Sec

                date = JamInfo.getUpcomingJamDate()

                value = str.format(
                    "The #1hgj starts in {0} (Sat {1} UTC)! More info at onehourgamejam.com #gamedev #indiedev #gamejam",
                    timeLeft, date)
                valueLen = value.count("")

                if valueLen <= 280:
                    await bot.say(tweetBot.tweet(value))
                else:
                    await bot.say("Tweet error: Too many characters to tweet")

            else:
                await bot.say(
                    "Not enough time has passed since last tweet (" +
                    str(round((28800 - offset.total_seconds()) / 3600, 3)) +
                    "h left)")
        else:
            print("Wrong role")
def jamReminderTask():
    yield from bot.wait_until_ready()

    while not bot.is_closed:

        start_time = "8PM UTC, Midday PST, 3PM EST, 9PM CET and 7AM AEDT."  # Daylight wasting
        # start_time = "8PM UTC, 1 PM PST, 4PM EST, 10PM CET and 6AM ACT." # Daylight savings

        next_jam_date = JamInfo.getUpcomingJamDate()

        tweet_content = "EMPTY"
        send_reminder = False

        # 24 hour reminder
        if check_time(next_jam_date - datetime.timedelta(hours=24)):
            tweet_content = "1 Hour Game Jam starts in 24h! That's at " + start_time + " https://onehourgamejam.com " + Config.twitter_hashtags

        # 16 hour reminder
        elif check_time(next_jam_date - datetime.timedelta(hours=16)):
            tweet_content = "1 Hour Game Jam starts in 16h! That's at " + start_time + " https://onehourgamejam.com " + Config.twitter_hashtags

        # 8 hour reminder
        elif check_time(next_jam_date - datetime.timedelta(hours=8)):
            tweet_content = "1 Hour Game Jam starts in 8h! That's at " + start_time + " https://onehourgamejam.com " + Config.twitter_hashtags

        # 4 hour reminder
        elif check_time(next_jam_date - datetime.timedelta(hours=4)):
            tweet_content = "1 Hour Game Jam starts in 4h! Participate at https://onehourgamejam.com " + Config.twitter_hashtags

        # 2 hour reminder
        elif check_time(next_jam_date - datetime.timedelta(hours=2)):
            tweet_content = "1 Hour Game Jam starts in 2h! Participate at https://onehourgamejam.com " + Config.twitter_hashtags

        # 1 hour reminder
        elif check_time(next_jam_date - datetime.timedelta(hours=1)):
            tweet_content = "1 Hour Game Jam starts in 1h! Join us on Discord at https://discord.gg/J86uTu9 " + Config.twitter_hashtags
            send_reminder = True

        # 20 min reminder
        elif check_time(next_jam_date - datetime.timedelta(minutes=20)):
            tweet_content = "1 Hour Game Jam starts in 20 minutes! Join us on Discord at https://discord.gg/J86uTu9 " + Config.twitter_hashtags

        # START reminder
        elif check_time(next_jam_date):
            jam_number = JamInfo.getCurrentJamNumber()
            jam_theme = JamInfo.getCurrentTheme()
            tweet_content = "1 hour game jam " + jam_number + " started. The theme is: '" + jam_theme + "'. Participate at https://onehourgamejam.com " + Config.twitter_hashtags

        # ---- Twitter ----
        if Config.usingTwitterBot and Config.usingAutoTwitterBot and tweet_content != "EMPTY":
            tweetBot.tweet(tweet_content)
            yield from bot.send_message(
                discord.Object(id=Config.DEBUG_modChannel),
                "<@111890906055020544>Tweet sent\n||" + tweet_content + "||")

        # ---- Send Jam Reminder ----
        if Config.usingJamReminder and send_reminder:
            yield from bot.send_message(
                discord.Object(id=Config.reminder_JamChannel),
                "@everyone The One Hour Game Jam starts within an hour! Hype<:lime:322433693111287838>!!"
            )

        elif not Config.usingJamReminder and send_reminder:
            yield from bot.send_message(
                discord.Object(id=Config.DEBUG_modChannel),
                ":speak_no_evil: I tried sending out a reminder but Liam was like \"urm no u aren't\" :speak_no_evil:"
            )

        yield from asyncio.sleep(60)  # Run task every 60 seconds