language support

This commit is contained in:
ggodot 2025-01-10 22:58:52 +01:00
parent 45664d0567
commit 49cc0f4131
3 changed files with 47 additions and 22 deletions

51
bot.py
View File

@ -16,8 +16,14 @@ async def on_ready():
@bot.slash_command(guild_ids=g_ids, name = "summary", description="Returns a Wikipedia summary")
async def summary(ctx, search: Option(str, description="What do you want to get summary for?", required = True)):
await ctx.channel.trigger_typing() # shows that bot is typing
async def summary(ctx, search: Option(str, description="What do you want to get summary for?", required = True), lang: Option(str, description="Language of wiki", required = False) = "en"):
await ctx.channel.trigger_typing() # that bot is typing
try:
wikipedia.set_lang(lang)
except:
await ctx.author.send("Your chosen language doesnt have dedicated wiki")
try: # sezene sumar a odesle
thesummary = wikipedia.summary(search, chars = 1950)
try:
@ -26,16 +32,19 @@ async def summary(ctx, search: Option(str, description="What do you want to get
await ctx.send(thesummary) # Send horsi, pouzije pokud nestihne response
except: # pokud nesezena musi vyhledavat
searchsummary = str(wikipedia.search(search, suggestion = True)).replace('(', '').replace(")", "").replace("'", "").replace('[', '').replace(']', '')
try:
await ctx.respond(f"I can't seem to find a summary for that.. DId you mean: {searchsummary}")
except:
await ctx.send(f"I can't seem to find a summary for that.. DId you mean: {searchsummary}")
await ctx.author.send(f"I can't seem to find a summary for that.. Did you mean: {searchsummary}")
@bot.slash_command(guild_ids=g_ids, name = "search", description="Search Wikipedia")
async def search(ctx, search: Option(str, description = "What do you want to search for?", required = True)):
async def search(ctx, search: Option(str, description = "What do you want to search for?", required = True), lang: Option(str, description="Language of wiki", required = False) = "en"):
await ctx.channel.trigger_typing() # shows that bot is typing
try:
wikipedia.set_lang(lang)
except:
await ctx.author.send("Your chosen language doesnt have dedicated wiki")
searchsearch = str(wikipedia.search(search, suggestion = True)).replace('(', '').replace(")", "").replace("'", "").replace('[', '').replace(']', '')
try:
await ctx.respond(searchsearch)
@ -45,33 +54,45 @@ async def search(ctx, search: Option(str, description = "What do you want to sea
@bot.slash_command(guild_ids=g_ids, name = "url", description="Get a URL to a page on Wikipedia")
async def search(ctx, search: Option(str, description = "What do you want to get URL for?", required = True)):
async def url(ctx, search: Option(str, description = "What do you want to get URL for?", required = True), lang: Option(str, description="Language of wiki", required = False) = "en"):
await ctx.channel.trigger_typing() # shows that bot is typing
try:
wikipedia.set_lang(lang)
except:
await ctx.author.send("Your chosen language doesnt have dedicated wiki")
try: # pokud sezenu sumary tak sezenu link
urlsummary = wikipedia.summary(search, auto_suggest = False)
search = search.lower().replace(" ","_").replace(" ","_")
try:
await ctx.respond(f"https://en.wikipedia.org/wiki/{search}")
await ctx.respond(f"https://{lang}.wikipedia.org/wiki/{search}")
except:
await ctx.send(f"https://en.wikipedia.org/wiki/{search}")
await ctx.send(f"https://{lang}.wikipedia.org/wiki/{search}")
except:
urlsearch = str(wikipedia.search(search, suggestion = True)).replace('(', '').replace(")", "").replace("'", "").replace('[', '').replace(']', '')
try:
await ctx.respond(f"https://en.wikipedia.org/wiki/{urlsearch}")
await ctx.respond(f"https://{lang}.wikipedia.org/wiki/{urlsearch}")
except:
await ctx.send(f"https://en.wikipedia.org/wiki/{urlsearch}")
await ctx.send(f"https://{lang}.wikipedia.org/wiki/{urlsearch}")
@bot.slash_command(guild_ids=g_ids, name = "random", description="Returns a random Wikipedia article")
async def search(ctx):
async def random(ctx, lang: Option(str, description = "Language of wiki", required = False) = "en"):
await ctx.channel.trigger_typing() # shows that bot is typing
try:
wikipedia.set_lang(lang)
except:
await ctx.author.send("Your chosen language doesnt have dedicated wiki")
ran_article = wikipedia.random().replace(" ", "_").replace(" ", "_")
try:
await ctx.respond(f"https://en.wikipedia.org/wiki/{ran_article}")
await ctx.respond(f"https://{lang}.wikipedia.org/wiki/{ran_article}")
except:
await ctx.send(f"https://en.wikipedia.org/wiki/{ran_article}")
await ctx.send(f"https://{lang}.wikipedia.org/wiki/{ran_article}")

View File

@ -5,8 +5,8 @@ After=syslog.target
[Service]
Type=simple
User=disbot
Group=disbot
User=bot
Group=bot
ProtectControlGroups=true
ProtectHome=true
@ -17,9 +17,9 @@ ProtectSystem=full
PrivateDevices=true
PrivateUsers=true
WorkingDirectory=/opt/disbot/
WorkingDirectory=/opt/bot/
ExecStart=/opt/disbot/env/bin/python3 /opt/disbot/disbot.py
ExecStart=/opt/bot/env/bin/python3 /opt/bot/bot.py
Restart=on-failure

View File

@ -19,11 +19,15 @@ mkdir /opt/bot/env/
python3 -m venv /opt/bot/env/
source /opt/bot/env/bin/activate
pip install -r req.txt
pip install discord
pip install py-cord
pip uninstall discord
pip install wikipedia
deactivate
mv bot.py /opt/disbot/
mkdir /opt/disbot/backup/
mv bot.py /opt/bot/
mkdir /opt/bot/backup/
chown -R bot:bot /opt/bot/