-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBan.cs
47 lines (42 loc) · 1.67 KB
/
Ban.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace bot.Handlers
{
public class Ban : ModuleBase<SocketCommandContext>
{
[Command("ban")]
public async Task BanAsync(SocketGuildUser user)
{
await Context.Message.DeleteAsync();
if (!Context.Message.Channel.Id.Equals(Global.SetupId))
{
var msg = await Context.Channel.SendMessageAsync
("You can use `!ban` command only in `setup` channel");
await Task.Delay(5000);
await Context.Channel.DeleteMessageAsync(msg);
return;
}
var banList = (await File.ReadAllLinesAsync("banlist.txt")).ToList();
if (banList.Contains($"{user.Id}"))
{
var msg = await Context.Channel.SendMessageAsync(
$"`{user.Username}` is already banned, if you want to unban `{user.Username}`" +
$" try `!unban {user.Username}`");
await Task.Delay(3000);
await Context.Channel.DeleteMessageAsync(msg);
return;
}
await File.AppendAllTextAsync("banlist.txt", $"{user.Id}\n");
var message = await Context.Channel.SendMessageAsync($"User `{user.Username}` was added to ban list");
await Task.Delay(3000);
await Context.Channel.DeleteMessageAsync(message);
}
}
}