rewrite wordpress

This commit is contained in:
insert 2024-08-07 15:20:39 -04:00
parent dbb0abd467
commit 7953b41a07
Signed by: insert
GPG key ID: A70775C389ACF105
2 changed files with 53 additions and 84 deletions

View file

@ -1,31 +0,0 @@
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 usercommands(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.user_command(
name="hello",
description="say hi anywhere!",
)
async def hellousercommand(self, inter: disnake.ApplicationCommandInteraction):
await inter.response.send_message("User installable commands everyone!")
@commands.user_command(
name="meonlytest",
description="say hi anywhere!",
)
async def meonlytestcommand(self, inter: disnake.ApplicationCommandInteraction):
await inter.response.send_message("User installable commands everyone!")
def setup(bot: commands.Bot):
bot.add_cog(usercommands(bot))

View file

@ -1,6 +1,6 @@
import disnake
from disnake.ext import commands
from disnake import TextInputStyle
import nextcord
from nextcord.ext import commands
from nextcord import TextInputStyle
from dotenv import load_dotenv
from random import randint
import aiosqlite as sqlite3
@ -11,59 +11,59 @@ import base64
from urllib.parse import urlparse
import os
class ApplicationModal(disnake.ui.Modal):
class BlogModal(nextcord.ui.Modal):
def __init__(self,endpoint,credentials):
self.endpoint = endpoint
self.credentials = credentials
components = [
disnake.ui.TextInput(
super().__init__(
f"create a post"
)
self.name = nextcord.ui.TextInput(
label="Title",
placeholder="Why pasta is better than bread",
custom_id="title",
style=TextInputStyle.short,
max_length=100,
),
disnake.ui.TextInput(
)
self.add_item(self.name)
self.author = nextcord.ui.TextInput(
label="Author",
placeholder="insertapp",
custom_id="author",
style=TextInputStyle.short,
max_length=32,
),
disnake.ui.TextInput(
)
self.add_item(self.author)
self.catergory = nextcord.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(
)
self.add_item(self.catergory)
self.content = nextcord.ui.TextInput(
label="content",
placeholder="words...",
custom_id="content",
style=TextInputStyle.paragraph,
max_length=4000,
),
disnake.ui.TextInput(
label="content2",
)
self.add_item(self.content)
self.contenttwo = nextcord.ui.TextInput(
label="contenttwo",
placeholder="optional more words...",
required = False,
custom_id="content2",
style=TextInputStyle.paragraph,
max_length=4000,
),
]
super().__init__(title=f"create a post", components=components)
)
self.add_item(self.contenttwo)
async def callback(self, inter: disnake.ModalInteraction):
filledoutresponse = inter.text_values
values = list(filledoutresponse.values())
async def callback(self, interaction: nextcord.Interaction) -> None:
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])
fromatedtitle = f"{self.name.value} by {self.author.value}"
formatedcontent = str(self.content.value)+" " + str(self.contenttwo.value)
catergory = int(self.catergory.value)
header = {'Authorization': 'Basic ' + token.decode('utf-8')}
post = {
'title' : fromatedtitle,
@ -73,19 +73,19 @@ class ApplicationModal(disnake.ui.Modal):
'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")
await interaction.response.send_message(f"<@666378959184855042> someone posted to the blog, you should probably approve it {responce.status_code}")
class wordpress(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.slash_command(
@nextcord.slash_command(
name="blog",
description="create a blog post",
)
async def blog(self, inter: disnake.ApplicationCommandInteraction):
await inter.response.send_modal(modal=ApplicationModal("https://pastablog.insertapp.net/wp-json/wp/v2/posts",self.bot.blogcredentials))
async def blog(self, interaction: nextcord.Interaction):
await interaction.response.send_modal(BlogModal("https://pastablog.insertapp.net/wp-json/wp/v2/posts",self.bot.blogcredentials))
def setup(bot: commands.Bot):
bot.add_cog(wordpress(bot))