From 1c748308f98a742d72174d3b83f99aee5a5eceb3 Mon Sep 17 00:00:00 2001 From: jjohnstondev Date: Thu, 26 Jan 2023 17:34:28 -0800 Subject: [PATCH] initia --- .woodpecker.yml | 12 ++++++++++ Dockerfile | 6 +++++ bot.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 .woodpecker.yml create mode 100644 Dockerfile create mode 100644 bot.py diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..1586b3b --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,12 @@ +pipeline: + publish-docker-image: + image: plugins/kaniko + settings: + registry: gitea.asdf.cafe + repo: gitea.asdf.cafe/abs3nt/lmgtfy-bot + tags: latest + dockerfile: Dockerfile + username: + from_secret: DOCKER_USERNAME + password: + from_secret: DOCKER_PASSWORD diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f58506d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3 +FROM gorialis/discord.py +RUN mkdir -p /usr/src/bot +WORKDIR /usr/src/bot +COPY . . +CMD [ "python3", "bot.py" ] diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..0ce0292 --- /dev/null +++ b/bot.py @@ -0,0 +1,60 @@ +import sys +from urllib.parse import quote_plus +import discord +import os +from discord.ext import commands + +intents = discord.Intents.default() + + +class LMGTFYBot(commands.Bot): + def __init__(self): + intents = discord.Intents.default() + intents.message_content = True + + super().__init__( + command_prefix=commands.when_mentioned_or('!'), + intents=intents + ) + + async def on_ready(self): + print(f'Logged in as {self.user})') + print('------') + + +class LMGTFY(discord.ui.View): + def __init__(self, query: str): + super().__init__() + query = quote_plus(query) + search_url = f'https://lmgtfy.asdf.cafe/?search={query}' + self.add_item(discord.ui.Button( + label='Google Search', + url=search_url) + ) + self.add_item(discord.ui.Button( + label='Feeling Lucky', + url=search_url+"&lucky=true") + ) + + +bot = LMGTFYBot() + + +@bot.command() +async def lmgtfy(ctx: commands.Context, search: str | None): + if search is None: + if ctx.message.reference is None: + return + if ctx.message.reference.message_id is None: + return + repl = await ctx.fetch_message(ctx.message.reference.message_id) + await repl.reply('I will do it for you :)', view=LMGTFY(repl.content)) + if search is not None: + await ctx.reply('I will do it for you :)', view=LMGTFY(search)) + return + +TOKEN = os.getenv("TOKEN") +if TOKEN is None: + sys.exit("TOKEN INVALID") + +bot.run(TOKEN)