PythonistaGuild / TwitchIO

An Async Bot/API wrapper for Twitch made in Python.
https://twitchio.dev
MIT License
798 stars 162 forks source link

On follow event? #198

Closed BuyMyMojo closed 2 years ago

BuyMyMojo commented 3 years ago

How do you do an event on new follow event using a bot class? is there a event_follow? like event_join?

I'm working on an auto bot ban.. bot, but I have no idea how to make it run this code on a fresh follow:

    async def event_join(self, channel, user):
        username = str(user.name)
        db = sql.connect("bots.db")
        cursor = db.execute("SELECT bot_name FROM bots")
        row = cursor.fetchall()
        row_to_list = []
        for names in row:
            row_to_list.append(names[0])
        if username in row_to_list:
            cursor2 = db.execute("SELECT times_banned FROM bots where bot_name = ?", (username,))
            row2 = cursor2.fetchone()
            times = [row2[0]]
            print(f"Found {username} in db, this is it's {int(times[0]) + 1} time")
            print(f"banned {username} from {channel.name}")
            await channel.send(f"/ban {username}")
            new_times = int(times[0]) + 1
            cursor3 = db.execute("UPDATE bots SET times_banned = ? where bot_name = ?", (new_times, username,))
            db.commit()
chillymosh commented 3 years ago

I believe this is something eventsub handles.

Also just an observation but you can change your for loop into list comprehension.

row_to_list = [names[0] for names in row]
BuyMyMojo commented 3 years ago

how would I write it? like event_sub(stuff here): ?

also thanks that's appreciated

BuyMyMojo commented 3 years ago

The only documentation says eventsub is coming soon, how do I use it? https://twitchio.readthedocs.io/en/latest/exts/eventsub.html?highlight=eventsub#eventsub-coming-soon

TSMRE commented 3 years ago

I believe this is something eventsub handles.

Also just an observation but you can change your for loop into list comprehension.

row_to_list = [names[0] for names in row]

I think the actual issue here is that you look submissive and breedable @chillymosh

BuyMyMojo commented 3 years ago

or can I use https://twitchio.readthedocs.io/en/latest/reference.html#twitchio.FollowEvent and how would I do that?

chillymosh commented 3 years ago

That's a dataclass which returns a FollowEvent object when you query the API. You should join the discord to discuss things further rather than filling up the issue with comments