-
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
Showing
13 changed files
with
439 additions
and
23 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 |
---|---|---|
@@ -1,14 +1,43 @@ | ||
# simplebot | ||
|
||
simplebot is a discord bot to entertain your server | ||
# 🤖 simplebot | ||
|
||
## Setup | ||
Make sure that you installed [.NET 7.0 or newer](https://dotnet.microsoft.com/en-us/download). | ||
Simple Discord bot to entertain your server | ||
## Bot Setup | ||
### Requirements: | ||
- [.NET 7.0 or newer](https://dotnet.microsoft.com/en-us/download). | ||
- [API Ninjas API Key](https://api-ninjas.com/api) | ||
- [Discord Application (bot)](https://discord.com/developers/applications) | ||
|
||
To use this bot, you need create a `config.json` file in root directory with the following content: | ||
### Setting up bot: | ||
- Create your aplication at Discord Developer Portal ![Image 1](https://cdn.discordapp.com/attachments/969140752766631969/1112370145889894400/ss1.png) | ||
|
||
- In your app, go to `Bot/Privileged Gateway Intents` and enable all settings ![Image 2](https://cdn.discordapp.com/attachments/969140752766631969/1112370606256705617/ss2.png) | ||
|
||
- Next, go to `OAuth2/URL Generator` and generate bot invite link ![Image 3](https://cdn.discordapp.com/attachments/969140752766631969/1112371418689183794/ss3.png) ![Image 4](https://cdn.discordapp.com/attachments/969140752766631969/1112371838278963230/ss4.png) | ||
|
||
- And here we go! We now created and configured your bot! | ||
|
||
### Getting Bot Token | ||
#### To get bot working, we need bot token | ||
- To get one, go to `Bot/Reset Token` and click `Reset Token`: ![Image 5](https://cdn.discordapp.com/attachments/969140752766631969/1112373709311852654/ss5.png) | ||
- If you have 2FA Authentication, you will be asked to prompt a 6 digit code | ||
- Voulà! Now we have Discord Bot Token! | ||
|
||
### Configurating `config.json`: | ||
- If you have bot token and API Ninja Api Key, create `config.json` file in root directory (where is `Program.cs` file) | ||
```json | ||
{ | ||
"token": "YOUR DISCORD BOT TOKEN", | ||
"prefix": ">" | ||
"token": "Discord bot token here", | ||
"prefix": ">", | ||
"api-ninjas_apikey": "API Ninjas API Key here" | ||
} | ||
``` | ||
|
||
|
||
## Acknowledgements | ||
|
||
- [RestSharp](https://restsharp.dev) | ||
- [Newtonsoft.Json](https://www.newtonsoft.com/json) | ||
- [DSharpPlus](https://dsharpplus.github.io/DSharpPlus/) | ||
- [Excuser API](https://excuser-three.vercel.app) | ||
|
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,5 @@ | ||
namespace simplebot.Api; | ||
|
||
public abstract class ApiRequest { | ||
private protected abstract string GetRequest(); | ||
} |
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,44 @@ | ||
using RestSharp; | ||
using Newtonsoft.Json; | ||
using simplebot.Classes; | ||
|
||
namespace simplebot.Api; | ||
|
||
public class GetExcuse : ApiRequest { | ||
private const string BaseUrl = "https://excuser-three.vercel.app/v1/"; | ||
|
||
private protected override string GetRequest() { | ||
try { | ||
var client = new RestClient(BaseUrl); | ||
var request = new RestRequest("excuse"); | ||
var response = client.Get(request).Content; | ||
|
||
if (response == null) { | ||
throw new Exception("Response is null"); | ||
} | ||
|
||
return response; | ||
} | ||
catch (Exception e) { | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} | ||
|
||
public List<ExcuseClass> ParseData() { | ||
try { | ||
var data = GetRequest(); | ||
var excuse = JsonConvert.DeserializeObject<List<ExcuseClass>>(data); | ||
|
||
if (excuse == null) { | ||
throw new Exception("Excuse is null"); | ||
} | ||
|
||
return excuse; | ||
} | ||
catch (Exception e) { | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} | ||
} |
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,47 @@ | ||
using Newtonsoft.Json; | ||
using RestSharp; | ||
using simplebot.Classes; | ||
|
||
namespace simplebot.Api; | ||
|
||
public class GetRandomFact : ApiRequest { | ||
private const string BaseUrl = "https://api.api-ninjas.com/v1/"; | ||
|
||
private protected override string GetRequest() { | ||
try { | ||
var apiKey = ConfigHandler.GetConfig().ApiNinjasApiKey; | ||
|
||
var client = new RestClient(BaseUrl); | ||
var request = new RestRequest("facts?limit=1").AddHeader("X-Api-Key", apiKey); | ||
|
||
var response = client.Get(request).Content; | ||
|
||
if (response == null) { | ||
throw new Exception("Response is null"); | ||
} | ||
|
||
return response; | ||
} | ||
catch (Exception e) { | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} | ||
|
||
public List<FactClass> ParseData() { | ||
try { | ||
var data = GetRequest(); | ||
var fact = JsonConvert.DeserializeObject<List<FactClass>>(data); | ||
|
||
if (fact == null) { | ||
throw new Exception("Fact is null"); | ||
} | ||
|
||
return fact; | ||
} | ||
catch (Exception e) { | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} | ||
} |
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
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,8 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace simplebot.Classes; | ||
|
||
public class ExcuseClass { | ||
[JsonProperty("excuse")] public string Excuse { get; set; } = null!; | ||
[JsonProperty("category")] public string Category { get; set; } = null!; | ||
} |
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,7 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace simplebot.Classes; | ||
|
||
public class FactClass { | ||
[JsonProperty("fact")] public string Fact { get; set; } = null!; | ||
} |
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,58 @@ | ||
using DSharpPlus.CommandsNext; | ||
using DSharpPlus.CommandsNext.Attributes; | ||
using DSharpPlus.Entities; | ||
using simplebot.Api; | ||
|
||
namespace simplebot.Commands; | ||
|
||
public class FunCommands : BaseCommandModule { | ||
[Command("8ball")] | ||
public async Task EightBallAsync(CommandContext ctx, string input) { | ||
var responses = new[] { | ||
"Yes", | ||
"No", | ||
"Maybe", | ||
"Ask again later", | ||
"I don't know", | ||
"I don't think so", | ||
"I think so", | ||
}; | ||
|
||
var embed = new DiscordEmbedBuilder() { | ||
Title = ":8ball: 8ball", | ||
Description = $"Question: {input}\nAnswer: {responses[new Random().Next(0, responses.Length)]}", | ||
Color = DiscordColor.Gold, | ||
Timestamp = DateTime.Now | ||
}; | ||
|
||
await ctx.Channel.SendMessageAsync(embed); | ||
} | ||
|
||
[Command("excuse")] | ||
public async Task ExcuseAsync(CommandContext ctx) { | ||
var excuse = new GetExcuse().ParseData(); | ||
|
||
var embed = new DiscordEmbedBuilder() { | ||
Title = "Random Excuse", | ||
Description = $"**Excuse:** `{excuse[0].Excuse}`\n**Category:** `{excuse[0].Category}`", | ||
Color = DiscordColor.Magenta, | ||
Timestamp = DateTime.Now | ||
}; | ||
|
||
await ctx.Channel.SendMessageAsync(embed); | ||
} | ||
|
||
[Command("randomfact")] | ||
public async Task RandomFactAsync(CommandContext ctx) { | ||
var fact = new GetRandomFact().ParseData(); | ||
|
||
var embed = new DiscordEmbedBuilder() { | ||
Title = ":question: Did you know?", | ||
Description = $"`{fact[0].Fact}`", | ||
Color = DiscordColor.DarkGreen, | ||
Timestamp = DateTime.Now | ||
}; | ||
|
||
await ctx.Channel.SendMessageAsync(embed); | ||
} | ||
} |
Oops, something went wrong.