-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a906ea5
Showing
25 changed files
with
650 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
TOKEN= | ||
GUILD_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
nostrum_boilerplate-*.tar | ||
|
||
# Temporary files, for example, from tests. | ||
/tmp/ | ||
|
||
# config files | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <https://unlicense.org> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Psglx :: Nostrum | ||
A random utility chat bot for Discord, made for private and fun usage. | ||
|
||
## 👩🏻💼 Getting started | ||
|
||
1. Install dependencies with `mix deps.get`. | ||
2. Rename `.env.example` to `.env`. | ||
3. Add your token and optionally developer guild id to the `.env` file. | ||
|
||
## 👩🏻🏫 Information | ||
> Versions | ||
* You **need** OTP Version 23 or higher. Latest Version is fine too, just not below 23/22. | ||
|
||
> Deployment | ||
* You do not need to push the commands, it is automatically done once you run the bot. | ||
|
||
## 🚴🏻 Up and running | ||
> Shell commands | ||
``` | ||
$ iex -S mix | ||
``` | ||
This will start the bot, if you make any additional changes you you have to stop the terminal with `CTRL + C` and then run the same iex command again. I might add auto-refresh later. | ||
|
||
> Bot commands | ||
``` | ||
/ping | ||
/random | ||
/goodmorning | ||
/goodnight | ||
``` | ||
Ping returns a simple "Ping Pong" while random returns a random quote from the `random.txt` file. You can modify that if you want like add more quotes/messages/facts ... | ||
|
||
## 🧏🏻 What I have used | ||
|
||
- [Elixir Programming Language](https://elixir-lang.org) | ||
|
||
- [Nostrum Discord Library](https://kraigie.github.io/nostrum/intro.html) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Config | ||
|
||
# develope mode while production isn't ready | ||
if Config.config_env() == :dev do | ||
DotenvParser.load_file(".env") | ||
end | ||
|
||
# define the token for the discord api wrapper | ||
config :nostrum, | ||
token: System.get_env("TOKEN") | ||
|
||
# for development mode; local slash commands | ||
config :psglx, | ||
env: Config.config_env(), | ||
GUILD_ID: System.get_env("GUILD_ID") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
https://i.imgur.com/zVFXlgN.gif | ||
https://i.imgur.com/8kolGy1.jpeg | ||
https://i.imgur.com/HGjV6Rk.gif | ||
https://i.imgur.com/qLioM3w.jpeg | ||
https://i.imgur.com/K3lh8e2.jpeg | ||
https://i.imgur.com/knvEUwa.jpeg | ||
https://i.imgur.com/lpIx2Dk.jpeg | ||
https://i.imgur.com/8mFkY55.jpeg | ||
https://i.imgur.com/bJlg6hw.jpeg | ||
https://i.imgur.com/JXPNjXnb.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
https://i.imgur.com/4DDzfxa.jpeg | ||
https://i.imgur.com/AmWThvwb.jpg | ||
https://i.imgur.com/MXarSsK.gif | ||
https://i.imgur.com/6MMNDqU.gif | ||
https://i.imgur.com/Rbdlo3B.jpeg | ||
https://i.imgur.com/CihyGAm.jpeg | ||
https://i.imgur.com/dm6HXna.jpeg | ||
https://i.imgur.com/ajmzbAF.jpeg | ||
https://i.imgur.com/VFbKXIl.jpeg | ||
https://i.imgur.com/3B3Zpy7.jpeg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Psglx.Application do | ||
# See https://hexdocs.pm/elixir/Application.html | ||
# for more information on OTP Applications | ||
@moduledoc false | ||
|
||
use Application | ||
|
||
@impl true | ||
def start(_type, _args) do | ||
children = [ | ||
# supervisor | ||
{Psglx.Consumer.Supervisor, []} | ||
# Psglx.Consumer.Supervisor | ||
] | ||
|
||
# See https://hexdocs.pm/elixir/Supervisor.html | ||
# for other strategies and supported options | ||
opts = [strategy: :one_for_one, name: Psglx.Supervisor] | ||
Supervisor.start_link(children, opts) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule Psglx.Command do | ||
@moduledoc """ | ||
Behaviour for application command implementations. | ||
""" | ||
|
||
alias Nostrum.Struct.Interaction | ||
|
||
@doc """ | ||
Used to define the spec for the command to be used for command registration. | ||
See https://hexdocs.pm/nostrum/slash-commands.html for more info on the | ||
required shape for the spec. | ||
""" | ||
@callback spec(name :: String.t()) :: map() | ||
|
||
@doc """ | ||
Called when the command is invoked. | ||
""" | ||
@callback handle_interaction(Interaction.t()) :: any() | ||
|
||
@doc """ | ||
Gets an option by it's name from the interaction. Returns `nil` if the | ||
option is not present in the interaction. | ||
""" | ||
@spec get_option(Interaction.t(), String.t()) :: | ||
Nostrum.Struct.ApplicationCommandInteractionData.options() | nil | ||
def get_option(interaction, name), | ||
do: Enum.find(interaction.data.options || [], fn %{name: n} -> n == name end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Psglx.Commands do | ||
@doc """ | ||
Handling and routing for commands and interactions. | ||
""" | ||
|
||
# Add your commands here. The command name will be passed as an argument to | ||
# your command's `spec/1` function, so you can see all of the command names | ||
# here and ensure they don't collide. | ||
@commands %{ | ||
"ping" => Psglx.Commands.Ping, | ||
"random" => Psglx.Commands.Random, | ||
"goodmorning" => Psglx.Commands.Morning, | ||
"goodnight" => Psglx.Commands.Night, | ||
"intro" => Psglx.Commands.Intro, | ||
"say" => Psglx.Commands.Say | ||
} | ||
|
||
@command_names for {name, _} <- @commands, do: name | ||
|
||
def register_commands() do | ||
commands = for {name, command} <- @commands, do: command.spec(name) | ||
|
||
# Global application commands take a couple of minutes to update in Discord, | ||
# so we use a test guild when in dev mode. | ||
if Application.get_env(:psglx, :env) == :dev do | ||
guild_id = Application.get_env(:psglx, :GUILD_ID) | ||
Nostrum.Api.bulk_overwrite_guild_application_commands(guild_id, commands) | ||
else | ||
Nostrum.Api.bulk_overwrite_global_application_commands(commands) | ||
end | ||
end | ||
|
||
def handle_interaction(interaction) do | ||
if interaction.data.name in @command_names do | ||
@commands[interaction.data.name].handle_interaction(interaction) | ||
else | ||
:ok | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
defmodule Psglx.Commands.Morning do | ||
@moduledoc false | ||
|
||
@behaviour Psglx.Command | ||
|
||
alias Nostrum.Api | ||
alias Psglx.Command | ||
|
||
@impl Command | ||
|
||
def spec(name) do | ||
%{ | ||
name: name, | ||
description: "Wish someone a good morning!", | ||
options: [ | ||
%{ | ||
type: 6, | ||
name: "user", | ||
description: "Who do you want to wish a good morning?", | ||
required: true | ||
} | ||
] | ||
} | ||
end | ||
|
||
@impl Command | ||
def handle_interaction(interaction) do | ||
%{value: name} = Command.get_option(interaction, "user") | ||
|
||
# fetch a random image | ||
random = | ||
File.stream!("goodmorning.txt") | ||
|> Enum.random() | ||
|
||
# wrap everything into an embed and send it into the channel | ||
embed = %Nostrum.Struct.Embed{ | ||
description: "Good morning <@#{name}>! ☕\n\nHave a nice day! 🌞", | ||
thumbnail: %Nostrum.Struct.Embed.Thumbnail{ | ||
url: random | ||
} | ||
} | ||
|
||
Api.create_interaction_response(interaction, %{ | ||
type: 4, | ||
data: %{embeds: [embed]} | ||
}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
defmodule Psglx.Commands.Night do | ||
@moduledoc false | ||
|
||
@behaviour Psglx.Command | ||
|
||
alias Nostrum.Api | ||
alias Psglx.Command | ||
|
||
@impl Command | ||
|
||
def spec(name) do | ||
%{ | ||
name: name, | ||
description: "Wish someone a good night!", | ||
options: [ | ||
%{ | ||
type: 6, | ||
name: "user", | ||
description: "Who do you want to wish a good night?", | ||
required: true | ||
} | ||
] | ||
} | ||
end | ||
|
||
@impl Command | ||
def handle_interaction(interaction) do | ||
%{value: name} = Command.get_option(interaction, "user") | ||
|
||
# fetch a random image | ||
random = | ||
File.stream!("goodnight.txt") | ||
|> Enum.random() | ||
|
||
# wrap everything into an embed and send it into the channel | ||
embed = %Nostrum.Struct.Embed{ | ||
description: "Good night <@#{name}>! 🌙\n\nSleep well and come back soon 😴", | ||
thumbnail: %Nostrum.Struct.Embed.Thumbnail{ | ||
url: random | ||
} | ||
} | ||
|
||
Api.create_interaction_response(interaction, %{ | ||
type: 4, | ||
data: %{embeds: [embed]} | ||
}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Psglx.Commands.Intro do | ||
@moduledoc false | ||
|
||
@behaviour Psglx.Command | ||
|
||
alias Nostrum.Api | ||
alias Psglx.Command | ||
|
||
@impl Command | ||
def spec(name) do | ||
%{ | ||
name: name, | ||
description: "A small intro of myself" | ||
} | ||
end | ||
|
||
@impl Command | ||
def handle_interaction(interaction) do | ||
embed = %Nostrum.Struct.Embed{ | ||
description: | ||
"Hello there #{interaction.user}, let me introduce myself!\n\nI'm \`Psglx\`, a bot made by **Koni#9521**.\nI have a lot of fun commands, and I'm constantly improving myself.\n\nI'm currently in **development**, so I'm not sure if I'll be able to do much more than what I already have.\n\nIf you have any questions, feel free to ask me!", | ||
thumbnail: %Nostrum.Struct.Embed.Thumbnail{ | ||
url: | ||
"https://images-ext-1.discordapp.net/external/rDN1l5js_itKv7r3H63hu9p81P-my2OiiqKAOXk3eWk/https/cdn.discordapp.com/avatars/945313842337042442/d2e7c0ed02fff6c1d314c2676f832b5f.png" | ||
}, | ||
footer: %Nostrum.Struct.Embed.Footer{ | ||
text: "Version: Psglx v1.3.0", | ||
icon_url: | ||
"https://images-ext-1.discordapp.net/external/rDN1l5js_itKv7r3H63hu9p81P-my2OiiqKAOXk3eWk/https/cdn.discordapp.com/avatars/945313842337042442/d2e7c0ed02fff6c1d314c2676f832b5f.png" | ||
}, | ||
# black | ||
color: 000_000 | ||
} | ||
|
||
Api.create_interaction_response(interaction, %{ | ||
type: 4, | ||
data: %{embeds: [embed]} | ||
}) | ||
end | ||
end |
Oops, something went wrong.