Coder Social home page Coder Social logo

m-davies / oghma Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 305 KB

Rules and references bot for discord d&d groups

License: MIT License

Python 99.16% Dockerfile 0.84%
discord discord-bot discord-py discord-api discordbot dnd dnd5e dnd-tools dnd5e-tools dungeons-and-dragons

oghma's Introduction

Oghma - Rules and references bot for discord dnd groups

Discord Bots

Overview

This is (yet another) discord bot for dnd groups on discord. The bot is pretty simple, it pulls in and parses data from Open5e to be displayed in discord. The whole Open5e database is utilised, meaning you can query the bot for dnd conditions, spells, monsters, whatever you need to lookup in the heat of the moment!

Table of Contents

How it works

The bot accepts a search phrase (known as an entity) which it feeds into the Open5e API, using various boring parsing and filtration techniques to ensure the request is legit. The bot first searches the API for an exact match, then for a partial one (i.e. dragon will match adult black dragon).

When it finds a match, it then uses the Scryfall search/ API to find a suitable picture for the response (if it doesn't have one in the first place) and sends the information back to the sender.

Sometimes more than one embed or even files need to be sent due to discord API character restrictions

Commands

  • Most commands enforce a word limit of 200 words per query.
  • The first word in an entity is used to optimise a query to Open5e:
    • For example, in the command /search monsters frost giant, frost giant will be treated as the entity, with frost being the word that optimises the search.
    • This means that you need to be careful where you put spaces and what word you place first in your query, as each will produce radically different results. So if you're getting weird results, try changing what word you lead with.
    • For example, /search monsters frostgiant produces no results as there are no monsters that include the full search term frostgiant.

/help

Display bot latency, author information (me!) and useful data. Pretty simple tbh.

/roll [CALCULATION]

  • Conducts a mathematical CALCULATION similar to rolling a dice and adding modifiers. The CALCULATION can include dice rolls (in the format [ROLLS]d[SIDES], such as 3d8) and logical operators.
  • Each roll result is recorded and displayed to the end user as well as all the steps taken by the command. ROLLS can be omitted (the bot will default to 1 roll) but SIDES must be equal to at least 2.
  • You can also use various operators to make complex sums and equations on your dice roll queries. Obviously, this means that standalone numbers (e.g. 4 7.2) are supported too. As of writing this, the currently supported operators are below.
"+" # Addition
"-" # Subtraction
"*" # Multiplication
"/" # Division
  • ROLLS and SIDES values are treated as single decimal point values but any standalone numbers are treated as decimal pointed. Meaning, /roll 1d20.5 would evaluate to /roll 1d20 but /roll 1d20.5 + 7.5 would evaluate to /roll 1d20 + 7.5.
  • Spaces must be placed between operators and arguments, otherwise it's likely your dice roll will not be calculated correctly. /roll 3d4 + 3 is fine but /roll 3d4+3 would only evaluate to /roll 3d4.

Image of Rolls Example

  • The steps are listed to show a user what order the program has calculated the final total in, as well as showing the running/cumulative total at that time of calculation.

/search [ENTITY]

  • Utilises the Open5e search/ directory to search the entire database for the ENTITY given.
  • search/ is like a directory (see below) that lists items in the database, but it also provides links and pointers to the original object in it's respective directory. This is how the bot will find your requested ENTITY.
  • This takes longer than /searchdir but provides a bigger area to search. Especially useful if you don't know what category your ENTITY is in.

/searchdir [DIRECTORY] [?ENTITY]

  • Searches a specific DIRECTORY in the Open5e database for the ENTITY. Check out the Open5e API Root Page for the supported directories.
  • If no ENTITY is provided, the bot will instead return all the searchable entities in the requested DIRECTORY, providing a handy reference for you in the future.
  • This is quicker than /search, with a smaller searchbase limited to the DIRECTORY. Handy if you need your result to be accurate.

/lst [ENTITY] [?DIRECTORY]

  • Returns a list of all the full and partial matches in Open5e to a requested ENTITY as well as their parent directories.
  • You could use this to narrow down repetitive search results or to find where a specific spell or item appears.
  • You can optionally add a DIRECTORY name to search for matches specifically within that directory or omit it to search the entire database for the requested entity.

How to add to your server

We have a top.gg page! Assuming the link in the image above doesn't work, click this text for a working link

Contributing

All contributions are welcome! Please join our discord and post a greeting in #contributing to get started. Also check out our Testing.md guide to setting up your own test bot to push new features and fixes (requires joining the discord)! It's just me working on the bot at the moment so any and all help would be appreciated.

Privacy

No user data is stored on who executed what command, just logs of what command was initiated anonymously are stored for debugging purposes.

oghma's People

Contributors

dependabot[bot] avatar m-davies avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

redeyed-vault

oghma's Issues

Allow bot to join voice chats and play cinematic music

Similar to what Rythm does, I'd like the ability for this bot to join a voice chat with a simple command and start playing cinematic music appropriate to the situation. I'm thinking something along the lines of:

  1. A new command (Maybe ?play dungeon | forest | city) that will force the bot to join the voice channel of the executer and play ambient music of the category specified
  2. Other music commands that will stop the music, skip the current song or kick the bot out of the voice chat

BREAKING CHANGES - bot is currently down due to Discord and discord.py changes

Essentially the bot is down due to numerous reasons and I have either been too busy or too ignorant to realise that until now. Therefore, I will attempt to fix the issues and get it up and running again, using this issue to track progress.

Feel free to comment any advice or requests you have for the bot in the meantime, I imagine I'll get some ideas while I'm going through all the shiny new Discord API stuff anyways.

Missing logs

We do have some limited logging in place but it could be better, especially when an error has been thrown

Add aliases to command output

We currently don't see any reference to our aliases in the bot output. When a user executes a command via an aliases, we should inform them that they have.

Improve the ?ping command

Right now, all the ping does is check if the bot is up. It would be nice if the command was updated to spit out diagnostic infomation and other useful stuff

Change all txt files to markdown

Discord supports markdown highlighting for small file snippets. We should make use of it and use discord's markdown highlighting instead of the current boring txt

Add a ?help command

Right now, all the commands have limited help text attached to them depending on how much info you offer to the command. However, a generalised help command would be a useful addition as I feel like every bot would need one. This command could offer stuff like:

  • The list of commands and examples of them executing
  • Where to open issues if things go wrong
  • Other info that's relevant to a ?help command

Add a dice roller

Will need to be flexible, use embeds and (if possible) have a history field that shows the most recent dice rolls

Provide better error handling

Describe the bug
Currently, the on_command_error func doesn't work as intended as we can't send an error stream via an embed. We should recify this to send some sort of output to the user on discord that something has gone wrong

Add a feature that will return a list of results

Is your feature request related to a problem? Please describe.
Currently the bot will only return the first matching term and ignores the rest. While this is good for perf reasons, we could do better by adding a new query that will return a list of results and the user can then optimise their query to pick the one that suits it best

Describe the solution you'd like
A new query that will produce a list of results rather than the first one

Describe alternatives you've considered
Using ?searchdir which while useful, does not filter the results down enough (e.g. it won't help when you're trying to find out all the giants in the database)

2nd Monster embed doesnt send

Example case ?searchdir monsters bule produces the following error

2020-06-05T21:01:44.222508+00:00 app[worker.1]: Traceback (most recent call last):
2020-06-05T21:01:44.222566+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 79, in wrapped
2020-06-05T21:01:44.222567+00:00 app[worker.1]: ret = await coro(*args, **kwargs)
2020-06-05T21:01:44.222597+00:00 app[worker.1]: File "bot.py", line 1336, in searchdir
2020-06-05T21:01:44.222597+00:00 app[worker.1]: await ctx.send(embed=response)
2020-06-05T21:01:44.222627+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/abc.py", line 823, in send
2020-06-05T21:01:44.222627+00:00 app[worker.1]: data = await state.http.send_message(channel.id, content, tts=tts, embed=embed, nonce=nonce)
2020-06-05T21:01:44.222653+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/http.py", line 222, in request
2020-06-05T21:01:44.222654+00:00 app[worker.1]: raise HTTPException(r, data)
2020-06-05T21:01:44.222731+00:00 app[worker.1]: discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
2020-06-05T21:01:44.222731+00:00 app[worker.1]: In embed.fields.2.value: This field is required
2020-06-05T21:01:44.222779+00:00 app[worker.1]:
2020-06-05T21:01:44.222780+00:00 app[worker.1]: The above exception was the direct cause of the following exception:
2020-06-05T21:01:44.222781+00:00 app[worker.1]:
2020-06-05T21:01:44.222819+00:00 app[worker.1]: Traceback (most recent call last):
2020-06-05T21:01:44.222888+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 863, in invoke
2020-06-05T21:01:44.222889+00:00 app[worker.1]: await ctx.command.invoke(ctx)
2020-06-05T21:01:44.222923+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 728, in invoke
2020-06-05T21:01:44.222924+00:00 app[worker.1]: await injected(*ctx.args, **ctx.kwargs)
2020-06-05T21:01:44.222960+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.6/site-packages/discord/ext/commands/core.py", line 88, in wrapped
2020-06-05T21:01:44.222961+00:00 app[worker.1]: raise CommandInvokeError(exc) from exc
2020-06-05T21:01:44.223017+00:00 app[worker.1]: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
2020-06-05T21:01:44.223017+00:00 app[worker.1]: In embed.fields.2.value: This field is required

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.