Skip to content

Commit

Permalink
Merge branch 'release/v1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Jun 18, 2023
2 parents 08e5a49 + ee2082c commit 1cb58ce
Show file tree
Hide file tree
Showing 26 changed files with 569 additions and 116 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# .NET Specified
bin/
obj/

Expand All @@ -8,6 +9,12 @@ riderModule.iml
.idea/
simplebot/config.json

# VSCode specified
# VSCode Specified
/.vscode/
simplebot/.vscode/

# Project related files
simplebot/Config/config.json
simplebot/Engine/LevelEngine/userinfo.json

simplebot/Engine/LevelEngine/rewards.json
49 changes: 49 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Contribution Guidelines
Thank you for your interest in contributing to the project! We appreciate your help in making this discord bot project even better. To ensure a smooth collaboration, please follow these guidelines when contributing to the project.

### Getting Started
To contribute to this project, follow these steps:

1. Fork the repository on GitHub.
2. Clone the forked repository to your local machine.
3. Make the necessary changes and improvements to the codebase.
4. Test your changes to ensure they work as expected.
5. Commit your changes with clear and descriptive commit messages.
6. Push the changes to your forked repository.
7. Submit a pull request to the main repository.

### Code Guidelines
Please adhere to the following code guidelines:

- Write clear and concise code that is easy to understand and maintain.
- Follow the existing coding style and conventions used in the project.
- Use meaningful variable and function names that accurately describe their purpose.
- Comment your code when necessary, especially for complex logic or non-obvious functionality.

### Testing
To maintain the project's quality, it is essential to test your changes. Here's how you can test the project:

- Run the existing tests to ensure that the project functions as expected.
- Write additional tests to cover the new features or changes you made.
- Ensure that all tests pass successfully before submitting your changes.

### Documentation
If you make changes that require updates to the documentation, please make sure to update the relevant parts of the project's documentation. This includes the README file, inline code comments, and any other relevant documentation files.

### Issue Tracking
If you find any bugs, have suggestions, or would like to request new features, please create an issue in the GitHub repository. Make sure to provide a clear and detailed description of the problem or enhancement you are proposing.

### Pull Request Process
To contribute your changes back to the main project, please follow these steps:

1. Ensure that your forked repository is up to date with the latest changes from the main repository.
2. Create a new branch for your changes, with a descriptive name.
3. Make your changes and commit them with clear and concise messages.
4. Push your branch to your forked repository.
5. Open a pull request from your branch to the main repository.
6. Provide a detailed description of the changes you made and the motivation behind them.
7. Wait for feedback and address any requested changes if necessary.
8. Once approved, your changes will be merged into the main repository.

### Conclusion
Thank you for considering contributing to this project! Your help is greatly appreciated. Let's work together to make this weather checking command-line tool even more useful and efficient. If you have any questions, feel free to reach out by creating an issue or contacting the project maintainers. Happy coding!
67 changes: 43 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
# 🤖 simplebot

Simple Discord bot to entertain your server
A Simple Discord bot to entertain your server

## Installation
### Requirements:
- [.NET 7.0 or newer](https://dotnet.microsoft.com/en-us/download)
- [API Ninjas API Key](https://api-ninjas.com/api)
![IMG1](https://cdn.discordapp.com/attachments/973146682499956746/1119970853896069211/readme_img.png)
## Prerequisites
- [.NET 7.0 Or newer](https://dotnet.microsoft.com/en-us/download)
- [API Ninjas Key](https://api-ninjas.com/api)
- [Discord Application (bot)](https://discord.com/developers/applications)

### Bot setup:
- Create your aplication at Discord Developer Portal
- In your app, go to `Bot/Privileged Gateway` Intents and enable all settings
- Next, go to `OAuth2/URL Generator` and generate bot invite link
- Go to `OAuth2/URL Generator` and generate bot invite link
- If you have 2FA Authentication, you will be asked to prompt a 6 digit code
- Create a JSON File in root directory:
## Installation

1. Create your [Discord Application](https://discord.com/developers/docs/getting-started#step-1-creating-an-app)
2. Clone the repository and open it in your IDE
3. Install dependencies
4. Create `config.json` file in `Config` directory with the following content:
```json
{
"token": "Discord bot token here",
"api-ninjas_apikey": "API Ninjas API Key here"
"token": "YOUR DISCORD BOT TOKEN",
"api-ninjas_apikey": "YOUR API NINJAS KEY",
"xp_multiplier": 0.5,
"level_cap": 20
}
```
- Voulà! Now just run solution and everyting should be working!
5. Run the project.
## Usage

This bot uses only [Slash Commands](https://support.discord.com/hc/en-us/articles/1500000368501-Slash-Commands-FAQ)

## Usage
This bot uses only slash commands, so to run a command, type: `/command`
To getting started, go to your Discord Server and type `/help`

![IMG2](https://cdn.discordapp.com/attachments/973146682499956746/1119977268777857024/IMG2.png)

![IMG3](https://cdn.discordapp.com/attachments/973146682499956746/1119977269335691354/IMG3.png)

To change the XP multiplier (amount of XP user will have after each message) can be change in `"xp_multiplier"` field in config file, and the requierd XP to new level can be modified in `"level_cap"` field
## Contributing

Contributions are always welcome!

Full command list is at `/help`
See `CONTRIBUTING.md` for ways to get started.

Please adhere to this project's `CODE_OF_CONDUCT.md`.


## Acknowledgements
### Frameworks:

#### Frameworks:
- [DSharpPlus](https://dsharpplus.github.io/DSharpPlus/)
- [RestSharp](https://restsharp.dev)
- [Newtonsoft.Json](https://www.newtonsoft.com/json)
- [DSharpPlus](https://dsharpplus.github.io/DSharpPlus/)

### API's:
- [Excuser API](https://excuser-three.vercel.app)
- [Memegen API](https://api.memegen.link/docs)
#### APIs:
- [API Ninjas](https://api-ninjas.com/api)
- [Excuse API](https://excuser-three.vercel.app)
- [Meme API](https://github.com/D3vd/Meme_Api)
- [API Ninjas](https://api-ninjas.com/api)
- [Memegen API](https://api.memegen.link/docs)


## License

This project is under [MIT](https://github.com/pazurkota/simplebot/blob/master/LICENSE) license

47 changes: 42 additions & 5 deletions simplebot/Bot.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Text;
using Newtonsoft.Json;
using DSharpPlus;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using DSharpPlus.SlashCommands;
using simplebot.Commands;
using simplebot.Configuration;
using simplebot.Engine.LevelEngine;

namespace simplebot;

Expand All @@ -17,7 +17,7 @@ public class Bot {
public InteractivityExtension Interactivity { get; private set; }

public async Task RunAsync() {
var json = ConfigHandler.GetConfig();
var json = Config.LoadConfig();

var config = new DiscordConfiguration {
Intents = DiscordIntents.All,
Expand All @@ -35,13 +35,15 @@ public async Task RunAsync() {

Client.Ready += OnClientReady;
Client.ComponentInteractionCreated += ButtonPressed;
Client.MessageCreated += MessageSendHandler;

var slashCommandConfig = Client.UseSlashCommands();

// slash commands registration
slashCommandConfig.RegisterCommands<UtilityCommands>();
slashCommandConfig.RegisterCommands<FunCommands>();
slashCommandConfig.RegisterCommands<ModerationCommands>();
slashCommandConfig.RegisterCommands<LevelCommands>();

await Client.ConnectAsync(new DiscordActivity("Powered by SimpleBot", ActivityType.Watching));
await Task.Delay(-1); // make the bot stay online
Expand All @@ -50,6 +52,39 @@ public async Task RunAsync() {
private Task OnClientReady(DiscordClient sender, ReadyEventArgs args) {
return Task.CompletedTask;
}

private Task MessageSendHandler(DiscordClient client, MessageCreateEventArgs e) {
LevelEngine levelEngine = new LevelEngine();
RoleRewards reward = new RoleRewards();
DiscordMember member = (DiscordMember) e.Author;

bool addedXp = levelEngine.AddXp(e.Author.Id, e.Guild.Id);
int level = levelEngine.GetUser(e.Author.Id, e.Guild.Id).Level;
bool canGiveReward = reward.CanGiveReward(level, e.Guild.Id);

if (!levelEngine.LeveledUp) return Task.CompletedTask;

if (canGiveReward) {
var role = e.Guild.GetRole(reward.GetReward(level, e.Guild.Id));
member.GrantRoleAsync(role);
}

DiscordEmbed embed = new DiscordEmbedBuilder() {
Title = "Level up!",
Description = $":tada: Congratulations, **{e.Author.Username}!** You leveled up!\n" +
$"Your new current level: `{level}`" +
$"{(canGiveReward ? $"\nYou have been rewarded with a role!" : "")}",
Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail() {
Url = e.Author.AvatarUrl
},
Color = DiscordColor.Green,
Timestamp = DateTime.Now
};

e.Channel.SendMessageAsync(e.Author.Mention, embed);

return Task.CompletedTask;
}

private Task ButtonPressed(DiscordClient client, ComponentInteractionCreateEventArgs e) {
DiscordEmbed embed;
Expand Down Expand Up @@ -97,7 +132,9 @@ private Task ButtonPressed(DiscordClient client, ComponentInteractionCreateEvent
"`/help` - Returns this help menu\n" +
"`/repo` - Return the link to the bot's GitHub repository\n" +
"`/support` - Return the link to the bot's support server\n" +
"`/uptime` - Returns the bot's uptime\n")
"`/uptime` - Returns the bot's uptime\n" +
"`/profile` - Returns your profile\n" +
"`/userxp [user] [xpToGive]` - Gives a specified amount of xp to a specified user\n")
.WithColor(DiscordColor.Azure)
.WithTimestamp(DateTime.Now);

Expand Down
33 changes: 16 additions & 17 deletions simplebot/Commands/FunCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using simplebot.Api;

namespace simplebot.Commands;

Expand Down Expand Up @@ -36,10 +35,10 @@ public async Task EightBallAsync(InteractionContext ctx, [Option("input", "Type
public async Task ExcuseAsync(InteractionContext ctx) {
await ctx.DeferAsync();

IDataFetcher fetcher = new ExcuseApiFetcher();
IDataParser parser = new ExcuseApiParser();
simplebot.Engine.Api.IDataFetcher fetcher = new simplebot.Engine.Api.ExcuseApiFetcher();
simplebot.Engine.Api.IDataParser parser = new simplebot.Engine.Api.ExcuseApiParser();

var excuse = new ExcuseApiProcessor(fetcher, parser).ProcessData();
var excuse = new simplebot.Engine.Api.ExcuseApiProcessor(fetcher, parser).ProcessData();

DiscordEmbed embed = new DiscordEmbedBuilder() {
Title = "Random Excuse",
Expand All @@ -55,10 +54,10 @@ public async Task ExcuseAsync(InteractionContext ctx) {
public async Task RandomFactAsync(InteractionContext ctx) {
await ctx.DeferAsync();

IDataFetcher fetcher = new FactApiFetcher();
IDataParser parser = new FactApiParser();
simplebot.Engine.Api.IDataFetcher fetcher = new simplebot.Engine.Api.FactApiFetcher();
simplebot.Engine.Api.IDataParser parser = new simplebot.Engine.Api.FactApiParser();

var fact = new FactApiProcessor(fetcher, parser).ProcessData();
var fact = new simplebot.Engine.Api.FactApiProcessor(fetcher, parser).ProcessData();

DiscordEmbed embed = new DiscordEmbedBuilder() {
Title = ":question: Did you know:",
Expand All @@ -74,10 +73,10 @@ public async Task RandomFactAsync(InteractionContext ctx) {
public async Task RandomJokeAsync(InteractionContext ctx) {
await ctx.DeferAsync();

IDataFetcher fetcher = new JokeApiFetcher();
IDataParser parser = new JokeApiParser();
simplebot.Engine.Api.IDataFetcher fetcher = new simplebot.Engine.Api.JokeApiFetcher();
simplebot.Engine.Api.IDataParser parser = new simplebot.Engine.Api.JokeApiParser();

var joke = new JokeApiProcessor(fetcher, parser).ProcessData();
var joke = new simplebot.Engine.Api.JokeApiProcessor(fetcher, parser).ProcessData();

DiscordEmbed embed = new DiscordEmbedBuilder() {
Title = ":rofl: Random joke:",
Expand All @@ -93,10 +92,10 @@ public async Task RandomJokeAsync(InteractionContext ctx) {
public async Task InsultAsync(InteractionContext ctx, [Option("user", "Choose a user to insult")] DiscordUser user) {
await ctx.DeferAsync();

IDataFetcher fetcher = new InsultApiFetcher();
ISingleDataParser parser = new InsultApiParser();
simplebot.Engine.Api.IDataFetcher fetcher = new simplebot.Engine.Api.InsultApiFetcher();
simplebot.Engine.Api.ISingleDataParser parser = new simplebot.Engine.Api.InsultApiParser();

var insult = new InsultApiProcessor(fetcher, parser).ProcessData();
var insult = new simplebot.Engine.Api.InsultApiProcessor(fetcher, parser).ProcessData();

DiscordEmbed embed = new DiscordEmbedBuilder() {
Title = $":face_with_symbols_over_mouth: Hey, {user.Username}:",
Expand All @@ -112,10 +111,10 @@ public async Task InsultAsync(InteractionContext ctx, [Option("user", "Choose a
public async Task RandomMemeAsync(InteractionContext ctx) {
await ctx.DeferAsync();

IDataFetcher fetcher = new MemeApiFetcher();
ISingleDataParser parser = new MemeApiParser();
simplebot.Engine.Api.IDataFetcher fetcher = new simplebot.Engine.Api.MemeApiFetcher();
simplebot.Engine.Api.ISingleDataParser parser = new simplebot.Engine.Api.MemeApiParser();

var meme = new MemeApiProcessor(fetcher, parser).ProcessData();
var meme = new simplebot.Engine.Api.MemeApiProcessor(fetcher, parser).ProcessData();

DiscordEmbed embed = new DiscordEmbedBuilder() {
Title = $"{meme.Title}",
Expand All @@ -136,7 +135,7 @@ public async Task GenerateMemeAsync(InteractionContext ctx,

await ctx.DeferAsync();

MemeGeneratorApi generator = new MemeGeneratorApi();
simplebot.Engine.Api.MemeGeneratorApi generator = new simplebot.Engine.Api.MemeGeneratorApi();
string content = generator.FetchData($"{image}/{top}%2F{bottom}");

DiscordEmbed embed = new DiscordEmbedBuilder() {
Expand Down
Loading

0 comments on commit 1cb58ce

Please sign in to comment.