From 62d54950b4833b256d9775d07785bff3c9c61281 Mon Sep 17 00:00:00 2001 From: Luke R Date: Mon, 9 Sep 2024 11:45:48 -0700 Subject: [PATCH] Adding wifi qr code generator to dale bot --- app/cogs/actual_utils.py | 35 ++++++++++++++++++++++++++++++++++- app/requirements.txt | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/cogs/actual_utils.py b/app/cogs/actual_utils.py index 11b16317..f1a807a7 100755 --- a/app/cogs/actual_utils.py +++ b/app/cogs/actual_utils.py @@ -1,7 +1,8 @@ -from discord.ext import commands from discord import option +from discord.ext import commands import discord import os +import tempfile class ActualUtils(commands.Cog): @@ -107,6 +108,38 @@ class ActualUtils(commands.Cog): except Exception: return await ctx.send_followup("Sorry, I'm unable to answer that") + @commands.slash_command( + guild_ids=None, + name="wifiqr", + description="Generate a qr code for your wifi network", + ) + @option( + name="network_name", + required=True, + description="The name of your network", + ) + @option( + name="password", required=True, description="Your wifi password", min_length=8 + ) + async def wifiqr(self, ctx, network_name, password): + import wifi_qrcode_generator.generator + + qr_code = wifi_qrcode_generator.generator.wifi_qrcode( + ssid=network_name, + hidden=False, + authentication_type="WPA", + password=password, + ) + + await ctx.defer() + try: + file, file_path = tempfile.mkstemp() + qr_code.make_image().save(file_path + ".png") + return await ctx.send_followup(file=discord.File(file_path + ".png")) + os.remove(file_path + ".png") + except Exception as e: + return await ctx.send_followup(f"Something went wrong,\n{e}") + @commands.slash_command( guld_ids=None, name="stock", diff --git a/app/requirements.txt b/app/requirements.txt index 1ab4147a..7237709a 100755 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -10,5 +10,6 @@ markovify openai owotext requests +wifi-qrcode-generator wolframalpha yfinance \ No newline at end of file