first commit
This commit is contained in:
commit
f680dd869b
6 changed files with 166 additions and 0 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
bin/
|
||||
obj/
|
||||
.env
|
||||
|
||||
databases/
|
||||
18
bot.csproj
Normal file
18
bot.csproj
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>false</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNetEnv" Version="3.1.1" />
|
||||
<PackageReference Include="DSharpPlus" Version="4.5.1" />
|
||||
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.5.1" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
18
commands/admin.cs
Normal file
18
commands/admin.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
public class HasAdminRole : CheckBaseAttribute
|
||||
{
|
||||
public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
|
||||
{
|
||||
bool hasAdminRole = ctx.Member?.Roles.Any(role => role.Name == "Admin") ?? false;
|
||||
if (!hasAdminRole)
|
||||
{
|
||||
await ctx.RespondAsync("Csicskáknak kuss van !");
|
||||
}
|
||||
return (hasAdminRole);
|
||||
}
|
||||
}
|
||||
|
||||
19
commands/hello.cs
Normal file
19
commands/hello.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.CommandsNext.Attributes;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Commands
|
||||
{
|
||||
public class Hello : BaseCommandModule
|
||||
{
|
||||
[Command("hello")]
|
||||
[Description("Beköszönés. Hello World")]
|
||||
[HasAdminRole]
|
||||
public async Task HelloCommand(CommandContext ctx)
|
||||
{
|
||||
await ctx.RespondAsync($"Szia! T3kerg0 vagyok!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
59
events/reaction-roles.cs
Normal file
59
events/reaction-roles.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using DSharpPlus;
|
||||
using DSharpPlus.EventArgs;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace T3k3rg0
|
||||
{
|
||||
public static class ReactionRoleHandler
|
||||
{
|
||||
public static void Register(DiscordClient discord)
|
||||
{
|
||||
discord.MessageReactionAdded += OnReactionAdded;
|
||||
discord.MessageReactionRemoved += OnReactionRemoved;
|
||||
}
|
||||
|
||||
private static async Task OnReactionAdded(DiscordClient client, MessageReactionAddEventArgs e)
|
||||
{
|
||||
if (e.User.IsBot) return;
|
||||
|
||||
var dbPath = Environment.GetEnvironmentVariable("DB_ROLES_LOC");
|
||||
using var connection = new SqliteConnection($"Data Source={dbPath}");
|
||||
connection.Open();
|
||||
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText = @"SELECT role_id FROM reaction_roles WHERE message_id = $message_id AND emoji = $emoji";
|
||||
command.Parameters.AddWithValue("$message_id", e.Message.Id);
|
||||
command.Parameters.AddWithValue("$emoji", e.Emoji.ToString());
|
||||
|
||||
var roleId = (long?)command.ExecuteScalar();
|
||||
if (roleId == null) return;
|
||||
|
||||
var member = await e.Guild.GetMemberAsync(e.User.Id);
|
||||
var role = e.Guild.GetRole((ulong)roleId);
|
||||
await member.GrantRoleAsync(role);
|
||||
}
|
||||
|
||||
private static async Task OnReactionRemoved(DiscordClient client, MessageReactionRemoveEventArgs e)
|
||||
{
|
||||
if (e.User.IsBot) return;
|
||||
|
||||
var dbPath = Environment.GetEnvironmentVariable("DB_ROLES_LOC");
|
||||
using var connection = new SqliteConnection($"Data Source={dbPath}");
|
||||
connection.Open();
|
||||
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText = @"SELECT role_id FROM reaction_roles WHERE message_id = $message_id AND emoji = $emoji";
|
||||
command.Parameters.AddWithValue("$message_id", e.Message.Id);
|
||||
command.Parameters.AddWithValue("$emoji", e.Emoji.ToString());
|
||||
|
||||
var roleId = (long?)command.ExecuteScalar();
|
||||
if (roleId == null) return;
|
||||
|
||||
var member = await e.Guild.GetMemberAsync(e.User.Id);
|
||||
var role = e.Guild.GetRole((ulong)roleId);
|
||||
await member.RevokeRoleAsync(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
program.cs
Normal file
47
program.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using DotNetEnv;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace T3k3rg0
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Env.Load(); // .env fájl betöltése
|
||||
|
||||
var discord = new DiscordClient(new DiscordConfiguration()
|
||||
{
|
||||
Token = Environment.GetEnvironmentVariable("DISCORD_BOT_TOKEN"),
|
||||
TokenType = TokenType.Bot,
|
||||
Intents = DiscordIntents.All,
|
||||
MinimumLogLevel = LogLevel.Debug,
|
||||
LoggerFactory = LoggerFactory.Create(builder =>
|
||||
{
|
||||
builder.AddConsole();
|
||||
builder.SetMinimumLevel(LogLevel.Debug);
|
||||
})
|
||||
});
|
||||
var commands = discord.UseCommandsNext(new CommandsNextConfiguration()
|
||||
{
|
||||
StringPrefixes = new[] { "!" },
|
||||
EnableDms = false,
|
||||
EnableMentionPrefix = true
|
||||
});
|
||||
|
||||
commands.RegisterCommands<Commands.Hello>();
|
||||
ReactionRoleHandler.Register(discord);
|
||||
|
||||
discord.Ready += async (s, e) =>
|
||||
{
|
||||
Console.WriteLine("T3k3rg0 elindult !");
|
||||
};
|
||||
|
||||
await discord.ConnectAsync();
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue