|
|
|
@ -1,8 +1,12 @@
@@ -1,8 +1,12 @@
|
|
|
|
|
import eulinchen.config as config |
|
|
|
|
from twitchio.ext import commands |
|
|
|
|
from twitchio import Message |
|
|
|
|
from twitchio import Message, Context, User |
|
|
|
|
from datetime import timedelta |
|
|
|
|
from eulinchen.lib.chat import PeriodicMessage |
|
|
|
|
from eulinchen.lib.twitch import Twitch |
|
|
|
|
from eulinchen.lib.twitch.exceptions import TwitchFollowNotFoundException, TwitchUserNotFoundException |
|
|
|
|
from eulinchen.lib.exceptions import InvalidArgumentException |
|
|
|
|
from eulinchen.twitch_responder.lib import raffle |
|
|
|
|
|
|
|
|
|
bot = commands.Bot( |
|
|
|
|
irc_token=config.twitch_tmi_token, |
|
|
|
@ -11,6 +15,12 @@ bot = commands.Bot(
@@ -11,6 +15,12 @@ bot = commands.Bot(
|
|
|
|
|
prefix='!', |
|
|
|
|
initial_channels=[config.twitch_bot_channel] |
|
|
|
|
) |
|
|
|
|
twitch = Twitch( |
|
|
|
|
config.twitch_client_id, |
|
|
|
|
config.twitch_client_secret, |
|
|
|
|
config.twitch_webhook_callback_url, |
|
|
|
|
config.timezone |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
# TODO: move stuff to db |
|
|
|
|
periodic_messages = [ |
|
|
|
@ -47,6 +57,7 @@ async def event_message(ctx: Message):
@@ -47,6 +57,7 @@ async def event_message(ctx: Message):
|
|
|
|
|
await bot.handle_commands(ctx) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# simple commands |
|
|
|
|
@bot.command(name='hallo') |
|
|
|
|
async def hallo(ctx): |
|
|
|
|
await ctx.send('/me Hallo, ich bin Eulinchen!') |
|
|
|
@ -62,5 +73,94 @@ async def pdb(ctx):
@@ -62,5 +73,94 @@ async def pdb(ctx):
|
|
|
|
|
await ctx.send('Link zur Personality Database: https://www.personality-database.com/') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# raffle commands |
|
|
|
|
@bot.command(name='rstart') |
|
|
|
|
async def rstart(ctx: Context): |
|
|
|
|
author: User = ctx.author |
|
|
|
|
if not author.is_mod: |
|
|
|
|
return |
|
|
|
|
raffle.enable() |
|
|
|
|
await ctx.send('Der Eintragezeitraum für das Gewinnspiel hat begonnen!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command(name='rstatus') |
|
|
|
|
async def rstatus(ctx: Context): |
|
|
|
|
author: User = ctx.author |
|
|
|
|
if not author.is_mod: |
|
|
|
|
return |
|
|
|
|
if raffle.check_raffle_active(): |
|
|
|
|
await ctx.send('Der Eintragezeitraum für das Gewinnspiel läuft grade!') |
|
|
|
|
else: |
|
|
|
|
await ctx.send('Der Eintragezeitraum für das Gewinnspiel läuft grade nicht!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command(name='rstop') |
|
|
|
|
async def rstop(ctx: Context): |
|
|
|
|
author: User = ctx.author |
|
|
|
|
if not author.is_mod: |
|
|
|
|
return |
|
|
|
|
raffle.disable() |
|
|
|
|
await ctx.send('Der Eintragezeitraum für das Gewinnspiel ist beendet!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command(name='gewinnspiel') |
|
|
|
|
async def rentry(ctx: Context): |
|
|
|
|
author: User = ctx.author |
|
|
|
|
if not raffle.check_raffle_active(): |
|
|
|
|
await ctx.send('Es läuft grade kein Eintragezeitraum für ein Gewinnspiel!') |
|
|
|
|
return |
|
|
|
|
try: |
|
|
|
|
follows_since = twitch.get_user_follows_since(author.id, config.amai_twitch_user_id) |
|
|
|
|
# TODO: make follow time configurable |
|
|
|
|
if follows_since < timedelta(hours=1): |
|
|
|
|
await ctx.send('Du folgst noch nicht lange genug!') |
|
|
|
|
return |
|
|
|
|
except TwitchFollowNotFoundException: |
|
|
|
|
await ctx.send('Du bist noch kein Follower!') |
|
|
|
|
return |
|
|
|
|
if raffle.add_raffle_entry(author.id): |
|
|
|
|
await ctx.send('Du bist nun im Lostopf!') |
|
|
|
|
else: |
|
|
|
|
await ctx.send('Du bist bereits im Lostopf!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command(name='gewinner') |
|
|
|
|
async def winner(ctx: Context): |
|
|
|
|
author: User = ctx.author |
|
|
|
|
if not author.is_mod: |
|
|
|
|
return |
|
|
|
|
winner_id = raffle.get_winner() |
|
|
|
|
if winner_id == -1: |
|
|
|
|
await ctx.send('Es nimmt aktuell niemand am Gewinnspiel teil!') |
|
|
|
|
return |
|
|
|
|
try: |
|
|
|
|
user = twitch.get_user(id=winner_id) |
|
|
|
|
await ctx.send('{winner} hat gewonnen! Herzlichen Glückwunsch! amaicmLove amaicmLove'.format( |
|
|
|
|
winner=user.display_name |
|
|
|
|
)) |
|
|
|
|
except TwitchUserNotFoundException: |
|
|
|
|
await ctx.send('Der Account des Gewinners konnte nicht gefunden werden!') |
|
|
|
|
except InvalidArgumentException: |
|
|
|
|
await ctx.send('Der Account des Gewinners konnte nicht gefunden werden!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command(name='rreset') |
|
|
|
|
async def winner(ctx: Context): |
|
|
|
|
author: User = ctx.author |
|
|
|
|
if not author.is_mod: |
|
|
|
|
return |
|
|
|
|
raffle.reset() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.command(name='rpool') |
|
|
|
|
async def winner(ctx: Context): |
|
|
|
|
author: User = ctx.author |
|
|
|
|
if not author.is_mod: |
|
|
|
|
return |
|
|
|
|
await ctx.send('Aktuell befinden sich {count} Teilnehmer im Lostopf.'.format( |
|
|
|
|
count=len(raffle.get_raffle_entries()) |
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
|
bot.run() |
|
|
|
|