Update 8-05-24 15:11
This commit is contained in:
parent
c633f75b77
commit
a0328e66fb
3 changed files with 281 additions and 0 deletions
133
speechbubble.py
Normal file
133
speechbubble.py
Normal file
|
@ -0,0 +1,133 @@
|
|||
import disnake
|
||||
from disnake.ext import commands
|
||||
from disnake import TextInputStyle
|
||||
from dotenv import load_dotenv
|
||||
from random import randint
|
||||
import aiosqlite as sqlite3
|
||||
import aiohttp
|
||||
from urllib.parse import urlparse
|
||||
import os
|
||||
|
||||
class ApplicationModal(disnake.ui.Modal):
|
||||
def __init__(self, user):
|
||||
self.victim = user
|
||||
components = [
|
||||
disnake.ui.TextInput(
|
||||
label="link to image",
|
||||
placeholder="https://media.discordapp.net/goofyimg.png",
|
||||
custom_id="image",
|
||||
style=TextInputStyle.short,
|
||||
max_length=400,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="chance: a 1 in x chance",
|
||||
placeholder="10",
|
||||
custom_id="chance: a 1 in x chance",
|
||||
style=TextInputStyle.short,
|
||||
max_length=5,
|
||||
),
|
||||
]
|
||||
super().__init__(title=f"create a speechbubble for {user.name}", components=components)
|
||||
|
||||
async def callback(self, inter: disnake.ModalInteraction):
|
||||
speechbubble = inter.text_values.items()
|
||||
embed = disnake.Embed(title="New speech bubble!", color=disnake.Colour.green())
|
||||
embed.add_field(
|
||||
name="User ID",
|
||||
value=self.victim.id,
|
||||
inline=False,
|
||||
)
|
||||
for key, value in speechbubble:
|
||||
if key == "image":
|
||||
if urlparse(value).netloc != 'media.discordapp.net' and urlparse(value).netloc != 'cdn.discordapp.com':
|
||||
await inter.response.send_message(f"for security reasons, the bot only accepts images from media.discordapp.net or cdn.discordapp.com", ephemeral=True)
|
||||
return
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(value) as response:
|
||||
if (response.status == 200) and (response.headers['content-type'] == "image/png" or response.headers['content-type'] == "image/jpeg" or response.headers['content-type'] == "image/jpg"):
|
||||
pass
|
||||
else:
|
||||
await inter.response.send_message(f"you did not supply an image {response.status} {response.headers['content-type']}", ephemeral=True)
|
||||
return
|
||||
else:
|
||||
if not value.isdigit():
|
||||
await inter.response.send_message("you supplied words for a number", ephemeral=True)
|
||||
return
|
||||
embed.add_field(
|
||||
name=key,
|
||||
value=value,
|
||||
inline=False,
|
||||
)
|
||||
await inter.response.send_message(f"<@{self.victim.id}> {inter.user.name} proposes the following speech bubble for you:", embed=embed, components=[
|
||||
disnake.ui.Button(label="Approve", style=disnake.ButtonStyle.success, custom_id="Approve"),
|
||||
disnake.ui.Button(label="Deny", style=disnake.ButtonStyle.danger, custom_id="Deny"),],)
|
||||
|
||||
|
||||
class speechbubble(commands.Cog):
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener("on_button_click")
|
||||
async def button_listener(self, inter: disnake.MessageInteraction):
|
||||
ogmsg = inter.message.embeds
|
||||
embed = ogmsg[0]
|
||||
if inter.user.id != int(embed.fields[0].value):
|
||||
await inter.response.send_message("you may not modify this speech bubble!", ephemeral=True)
|
||||
return
|
||||
if inter.component.custom_id == "Approve":
|
||||
embed.add_field(
|
||||
name="Status",
|
||||
value="Approved",
|
||||
inline=False,
|
||||
)
|
||||
await inter.response.edit_message(embed=embed, components=[])
|
||||
await self.bot.cur.execute(f"""
|
||||
INSERT INTO userinfo VALUES
|
||||
({inter.guild_id}, {int(embed.fields[0].value)}, '{embed.fields[1].value}', {int(embed.fields[2].value)})
|
||||
""")
|
||||
await self.bot.db.commit()
|
||||
return
|
||||
if inter.component.custom_id == "Deny":
|
||||
embed.add_field(
|
||||
name="Status",
|
||||
value="Denied",
|
||||
inline=False,
|
||||
)
|
||||
await inter.response.edit_message(embed=embed, components=[])
|
||||
return
|
||||
|
||||
@commands.Cog.listener('on_message')
|
||||
async def on_message(self,message):
|
||||
res = await self.bot.cur.execute(f"SELECT imagelink, chance FROM userinfo WHERE serverid = {message.guild.id} AND userid = {message.author.id} ORDER BY RANDOM() LIMIT 1")
|
||||
try:
|
||||
imagelink, chance = await res.fetchone()
|
||||
except TypeError:
|
||||
return
|
||||
if randint(1, chance) == 1:
|
||||
await message.channel.send(imagelink)
|
||||
|
||||
@commands.slash_command(
|
||||
name="create",
|
||||
description="create a speech bubble for a user",
|
||||
)
|
||||
async def create(self, inter: disnake.ApplicationCommandInteraction, victim: disnake.Member = commands.Param(name="victim")):
|
||||
if inter.user.id == victim.id:
|
||||
await inter.response.send_message("you may not assign yourself a speech bubble!", ephemeral=True)
|
||||
return
|
||||
await inter.response.send_modal(modal=ApplicationModal(victim))
|
||||
|
||||
@commands.slash_command(
|
||||
name="removeme",
|
||||
description="Removes you from the database",
|
||||
)
|
||||
async def removeme(self, inter: disnake.ApplicationCommandInteraction, universal: str = commands.Param(choices=["yes", "no"])):
|
||||
if universal == "yes":
|
||||
await self.bot.cur.execute(f"DELETE FROM userinfo WHERE userid = {inter.user.id}")
|
||||
elif universal == "no":
|
||||
await self.bot.cur.execute(f"DELETE FROM userinfo WHERE userid = {inter.user.id} AND serverid = {inter.guild_id}")
|
||||
await self.bot.db.commit()
|
||||
await inter.response.send_message("Done!", ephemeral=True)
|
||||
|
||||
def setup(bot: commands.Bot):
|
||||
bot.add_cog(speechbubble(bot))
|
57
transcription.py
Normal file
57
transcription.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
import disnake
|
||||
from disnake.ext import commands
|
||||
import os
|
||||
from os import path
|
||||
import asyncio
|
||||
from pydub import AudioSegment
|
||||
import numpy as np
|
||||
import speech_recognition as sr
|
||||
|
||||
def prepaudio(audiofile):
|
||||
st = sr.Recognizer()
|
||||
oggfile = AudioSegment.from_ogg(audiofile)
|
||||
oggfile.export("audio.wav", format="wav")
|
||||
convertemessage = sr.AudioFile("audio.wav")
|
||||
with convertemessage as sounds:
|
||||
transcribeaudo = st.record(sounds)
|
||||
return transcribeaudo
|
||||
|
||||
class transcription(commands.Cog):
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
self.st = sr.Recognizer()
|
||||
|
||||
|
||||
@commands.message_command(name="Transcribe Using Sphinx")
|
||||
async def transcribesphinx(self, inter: disnake.ApplicationCommandInteraction, message: disnake.Message):
|
||||
try:
|
||||
await inter.response.defer(ephemeral='true')
|
||||
await message.attachments[0].save("audio.ogg")
|
||||
embed=disnake.Embed(title="Audio Transcription",description=self.st.recognize_sphinx(prepaudio("audio.ogg")), color=0x3584e4)
|
||||
embed.set_author(name=message.author.display_name, url=message.jump_url, icon_url=message.author.display_avatar)
|
||||
embed.set_footer(text="Accuracy not guaranteed")
|
||||
await inter.edit_original_message(embed=embed)
|
||||
os.remove("audio.ogg")
|
||||
os.remove("audio.wav")
|
||||
except Exception as e:
|
||||
await inter.edit_original_message(content=f'an error appears to have occoured please report it to the developer: {e}')
|
||||
|
||||
@commands.message_command(name="Transcribe Using Google")
|
||||
async def transcribegoogle(self, inter: disnake.ApplicationCommandInteraction, message: disnake.Message):
|
||||
try:
|
||||
await inter.response.defer(ephemeral='true')
|
||||
await message.attachments[0].save("audio.ogg")
|
||||
# WARNING Google is propritary, consider disabling however sphynix is currently not very good so this provides an option
|
||||
embed=disnake.Embed(title="Audio Transcription",description=self.st.recognize_google(prepaudio("audio.ogg")), color=0x3584e4)
|
||||
embed.set_author(name=message.author.display_name, url=message.jump_url, icon_url=message.author.display_avatar)
|
||||
embed.set_footer(text="Accuracy not guaranteed")
|
||||
await inter.edit_original_message(embed=embed)
|
||||
await asyncio.sleep(3)
|
||||
os.remove("audio.ogg")
|
||||
os.remove("audio.wav")
|
||||
except Exception as e:
|
||||
await inter.edit_original_message(content=f'an error appears to have occoured please report it to the developer: {e}')
|
||||
|
||||
def setup(bot: commands.Bot):
|
||||
bot.add_cog(transcription(bot))
|
91
wordpress.py
Normal file
91
wordpress.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
import disnake
|
||||
from disnake.ext import commands
|
||||
from disnake import TextInputStyle
|
||||
from dotenv import load_dotenv
|
||||
from random import randint
|
||||
import aiosqlite as sqlite3
|
||||
import requests
|
||||
import json
|
||||
from datetime import datetime
|
||||
import base64
|
||||
from urllib.parse import urlparse
|
||||
import os
|
||||
|
||||
class ApplicationModal(disnake.ui.Modal):
|
||||
def __init__(self,endpoint,credentials):
|
||||
self.endpoint = endpoint
|
||||
self.credentials = credentials
|
||||
components = [
|
||||
disnake.ui.TextInput(
|
||||
label="Title",
|
||||
placeholder="Why pasta is better than bread",
|
||||
custom_id="title",
|
||||
style=TextInputStyle.short,
|
||||
max_length=100,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="Author",
|
||||
placeholder="insertapp",
|
||||
custom_id="author",
|
||||
style=TextInputStyle.short,
|
||||
max_length=32,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="catergory id, if you don't know put 1",
|
||||
placeholder="1",
|
||||
custom_id="catergory",
|
||||
style=TextInputStyle.short,
|
||||
max_length=2,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="content",
|
||||
placeholder="words...",
|
||||
custom_id="content",
|
||||
style=TextInputStyle.paragraph,
|
||||
max_length=4000,
|
||||
),
|
||||
disnake.ui.TextInput(
|
||||
label="content2",
|
||||
placeholder="optional more words...",
|
||||
required = False,
|
||||
custom_id="content2",
|
||||
style=TextInputStyle.paragraph,
|
||||
max_length=4000,
|
||||
),
|
||||
]
|
||||
super().__init__(title=f"create a post", components=components)
|
||||
|
||||
async def callback(self, inter: disnake.ModalInteraction):
|
||||
filledoutresponse = inter.text_values
|
||||
values = list(filledoutresponse.values())
|
||||
token = base64.b64encode(self.credentials.encode())
|
||||
dt = datetime.now()
|
||||
date = dt.isoformat()
|
||||
fromatedtitle = f"{values[0]} by {values[1]}"
|
||||
formatedcontent = str(values[3])+" " + str(values[4])
|
||||
catergory = int(values[2])
|
||||
header = {'Authorization': 'Basic ' + token.decode('utf-8')}
|
||||
post = {
|
||||
'title' : fromatedtitle,
|
||||
'status' : 'pending',
|
||||
'content' : formatedcontent,
|
||||
'categories': catergory,
|
||||
'date' : date
|
||||
}
|
||||
responce = requests.post(self.endpoint, headers=header, json=post)
|
||||
await inter.response.send_message("<@666378959184855042> someone posted to the blog, you should probably approve it")
|
||||
|
||||
|
||||
class wordpress(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.slash_command(
|
||||
name="blog",
|
||||
description="create a blog post",
|
||||
)
|
||||
async def blog(self, inter: disnake.ApplicationCommandInteraction):
|
||||
await inter.response.send_modal(modal=ApplicationModal(self.bot.blog.endpoint,self.bot.blog.credentials))
|
||||
|
||||
def setup(bot: commands.Bot):
|
||||
bot.add_cog(wordpress(bot))
|
Loading…
Reference in a new issue