Add kick command
This commit is contained in:
parent
7167ea3ebc
commit
001b937415
3 changed files with 50 additions and 5 deletions
|
@ -3,7 +3,9 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Discord.WebSocket;
|
||||||
using Geekbot.net.Lib;
|
using Geekbot.net.Lib;
|
||||||
|
using StackExchange.Redis;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands
|
namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
|
@ -15,11 +17,15 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
private readonly IUserRepository _userRepository;
|
private readonly IUserRepository _userRepository;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
private readonly IDatabase _redis;
|
||||||
|
private readonly DiscordSocketClient _client;
|
||||||
|
|
||||||
public Mod(IUserRepository userRepositry, IErrorHandler errorHandler)
|
public Mod(IUserRepository userRepositry, IErrorHandler errorHandler, IDatabase redis, DiscordSocketClient client)
|
||||||
{
|
{
|
||||||
_userRepository = userRepositry;
|
_userRepository = userRepositry;
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
|
_redis = redis;
|
||||||
|
_client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("namehistory", RunMode = RunMode.Async)]
|
[Command("namehistory", RunMode = RunMode.Async)]
|
||||||
|
@ -40,7 +46,45 @@ namespace Geekbot.net.Commands
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_errorHandler.HandleCommandException(e, Context, "Modchannel doesn't seem to exist, please set one with `!admin modchannel [channelId]`");
|
_errorHandler.HandleCommandException(e, Context, $"I don't have enough permissions to give {user.Username} that role");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("kick", RunMode = RunMode.Async)]
|
||||||
|
[Remarks(CommandCategories.Admin)]
|
||||||
|
[Summary("Ban a user")]
|
||||||
|
public async Task kick([Summary("@user")] IUser userNormal, [Summary("reason"), Remainder] string reason)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var user = (IGuildUser)userNormal;
|
||||||
|
if (string.IsNullOrEmpty(reason))
|
||||||
|
{
|
||||||
|
reason = "No reason provided";
|
||||||
|
}
|
||||||
|
|
||||||
|
await user.KickAsync();
|
||||||
|
await user.GetOrCreateDMChannelAsync().Result.SendMessageAsync(
|
||||||
|
$"You have been kicked from {Context.Guild.Name} for the following reason: \"{reason}\"");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var modChannelId = ulong.Parse(_redis.HashGet($"{Context.Guild.Id}:Settings", "ModChannel"));
|
||||||
|
var modChannel = (ISocketMessageChannel) _client.GetChannel(modChannelId);
|
||||||
|
var eb = new EmbedBuilder();
|
||||||
|
eb.Title = "Kicked";
|
||||||
|
eb.AddInlineField("User", user.Username);
|
||||||
|
eb.AddInlineField("By Mod", Context.User.Username);
|
||||||
|
eb.AddField("Reason", reason);
|
||||||
|
await modChannel.SendMessageAsync("", false, eb.Build());
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
await ReplyAsync($"{user.Username} was kicked for the following reason: \"{reason}\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_errorHandler.HandleCommandException(e, Context, "I don't have enough permissions to kick someone");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,10 +53,11 @@ namespace Geekbot.net.Commands
|
||||||
[Command(RunMode = RunMode.Async)]
|
[Command(RunMode = RunMode.Async)]
|
||||||
[Remarks(CommandCategories.Helpers)]
|
[Remarks(CommandCategories.Helpers)]
|
||||||
[Summary("Get a role by mentioning it.")]
|
[Summary("Get a role by mentioning it.")]
|
||||||
public async Task giveRole([Summary("roleNickname")] string roleName)
|
public async Task giveRole([Summary("roleNickname")] string roleNameRaw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var roleName = roleNameRaw.ToLower();
|
||||||
if (_redis.HashExists($"{Context.Guild.Id}:RoleWhitelist", roleName))
|
if (_redis.HashExists($"{Context.Guild.Id}:RoleWhitelist", roleName))
|
||||||
{
|
{
|
||||||
var guildUser = (IGuildUser) Context.User;
|
var guildUser = (IGuildUser) Context.User;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<PackageReference Include="Nancy" Version="2.0.0-clinteastwood" />
|
<PackageReference Include="Nancy" Version="2.0.0-clinteastwood" />
|
||||||
<PackageReference Include="Nancy.Hosting.Self" Version="2.0.0-clinteastwood" />
|
<PackageReference Include="Nancy.Hosting.Self" Version="2.0.0-clinteastwood" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||||
<PackageReference Include="Overwatch.Net" Version="3.0.0-alpha" />
|
<PackageReference Include="Overwatch.Net" Version="3.0.0" />
|
||||||
<PackageReference Include="PokeApi.NET" Version="1.1.0" />
|
<PackageReference Include="PokeApi.NET" Version="1.1.0" />
|
||||||
<PackageReference Include="Serilog" Version="2.6.0-dev-00894" />
|
<PackageReference Include="Serilog" Version="2.6.0-dev-00894" />
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1-dev-00757" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1-dev-00757" />
|
||||||
|
@ -39,6 +39,6 @@
|
||||||
<PackageReference Include="System.Runtime.Serialization.Primitives">
|
<PackageReference Include="System.Runtime.Serialization.Primitives">
|
||||||
<Version>4.3.0</Version>
|
<Version>4.3.0</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Utf8Json" Version="1.1.0" />
|
<PackageReference Include="Utf8Json" Version="1.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in a new issue