.videocall and .logserver, new discord.net version

This commit is contained in:
Master Kwoth 2016-02-17 22:37:28 +01:00
parent 00e48be7fe
commit e2d6d8aebf
13 changed files with 129 additions and 22 deletions

View File

@ -265,7 +265,7 @@ namespace NadekoBot.Classes.Music {
Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey."); Console.WriteLine("Nothing was buffered, try another song and check your GoogleApikey.");
} }
int blockSize = 1920 * NadekoBot.client.Services.Get<AudioService>().Config.Channels; int blockSize = 1920 * NadekoBot.client.GetService<AudioService>().Config.Channels;
byte[] voiceBuffer = new byte[blockSize]; byte[] voiceBuffer = new byte[blockSize];
if (parent.OnStarted != null) if (parent.OnStarted != null)

View File

@ -28,7 +28,7 @@ namespace NadekoBot
static NadekoStats() { } static NadekoStats() { }
private NadekoStats() { private NadekoStats() {
_service = NadekoBot.client.Services.Get<CommandService>(); _service = NadekoBot.client.GetService<CommandService>();
_client = NadekoBot.client; _client = NadekoBot.client;
_statsSW = new Stopwatch(); _statsSW = new Stopwatch();

View File

@ -40,7 +40,7 @@ namespace NadekoBot.Classes {
if (string.IsNullOrWhiteSpace(mod)) if (string.IsNullOrWhiteSpace(mod))
throw new ArgumentNullException(nameof(mod)); throw new ArgumentNullException(nameof(mod));
foreach (var m in NadekoBot.client.Modules().Modules) { foreach (var m in NadekoBot.client.GetService<ModuleService>().Modules) {
if (m.Name.ToLower().Equals(mod.ToLower())) if (m.Name.ToLower().Equals(mod.ToLower()))
return m.Name; return m.Name;
} }
@ -51,7 +51,7 @@ namespace NadekoBot.Classes {
if (string.IsNullOrWhiteSpace(commandText)) if (string.IsNullOrWhiteSpace(commandText))
throw new ArgumentNullException(nameof(commandText)); throw new ArgumentNullException(nameof(commandText));
foreach (var com in NadekoBot.client.Services.Get<CommandService>().AllCommands) { foreach (var com in NadekoBot.client.GetService<CommandService>().AllCommands) {
if (com.Text.ToLower().Equals(commandText.ToLower())) if (com.Text.ToLower().Equals(commandText.ToLower()))
return com.Text; return com.Text;
} }

View File

@ -13,7 +13,7 @@ namespace NadekoBot
string helpstr = "**COMMANDS DO NOT WORK IN PERSONAL MESSAGES**\nOfficial repo: **github.com/Kwoth/NadekoBot/**"; string helpstr = "**COMMANDS DO NOT WORK IN PERSONAL MESSAGES**\nOfficial repo: **github.com/Kwoth/NadekoBot/**";
string lastCategory = ""; string lastCategory = "";
foreach (var com in client.Services.Get<CommandService>().AllCommands) foreach (var com in client.GetService<CommandService>().AllCommands)
{ {
if (com.Category != lastCategory) if (com.Category != lastCategory)
{ {
@ -38,7 +38,7 @@ namespace NadekoBot
string helpstr = "Official repo: **github.com/Kwoth/NadekoBot/** \n"; string helpstr = "Official repo: **github.com/Kwoth/NadekoBot/** \n";
string lastCategory = ""; string lastCategory = "";
foreach (var com in client.Services.Get<CommandService>().AllCommands) { foreach (var com in client.GetService<CommandService>().AllCommands) {
if (com.Category != lastCategory) { if (com.Category != lastCategory) {
helpstr += "\n### " + com.Category + " \n"; helpstr += "\n### " + com.Category + " \n";
helpstr += "Command and aliases | Description | Usage\n"; helpstr += "Command and aliases | Description | Usage\n";

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using Discord.Commands;
using Discord;
namespace NadekoBot.Commands {
class LogCommand : DiscordCommand {
public LogCommand() : base() {
NadekoBot.client.MessageReceived += MsgRecivd;
NadekoBot.client.MessageDeleted += MsgDltd;
NadekoBot.client.MessageUpdated += MsgUpdtd;
NadekoBot.client.UserUpdated += UsrUpdtd;
}
ConcurrentDictionary<Server, Channel> logs = new ConcurrentDictionary<Server, Channel>();
public override Func<CommandEventArgs, Task> DoFunc() => async e => {
if (e.User.Id != NadekoBot.OwnerID ||
e.User.Server.Owner.Id != e.User.Id)
return;
Channel ch;
if (!logs.TryRemove(e.Server, out ch)) {
logs.TryAdd(e.Server, e.Channel);
await e.Channel.SendMessage($"**I WILL BEGIN LOGGING SERVER ACTIVITY IN THIS CHANNEL**");
return;
}
await e.Channel.SendMessage($"**NO LONGER LOGGIN IN {ch.Mention} CHANNEL**");
};
private async void MsgRecivd(object sender, MessageEventArgs e) {
if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.client.CurrentUser.Id)
return;
Channel ch;
if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch)
return;
await ch.SendMessage($"`Type:` **Message received** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n`{e.User}:` {e.Message.Text}");
}
private async void MsgDltd(object sender, MessageEventArgs e) {
if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.client.CurrentUser.Id)
return;
Channel ch;
if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch)
return;
await ch.SendMessage($"`Type:` **Message deleted** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n`{e.User}:` {e.Message.Text}");
}
private async void MsgUpdtd(object sender, MessageUpdatedEventArgs e) {
if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.client.CurrentUser.Id)
return;
Channel ch;
if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch)
return;
await ch.SendMessage($"`Type:` **Message updated** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n**BEFORE**: `{e.User}:` {e.Before.Text}\n---------------\n**AFTER**: `{e.User}:` {e.Before.Text}");
}
private async void UsrUpdtd(object sender, UserUpdatedEventArgs e) {
string str = $"`Type:` **User updated** `Time:` **{DateTime.Now}**\n";
if (e.Before.Name != e.After.Name)
str += $"Name changed from `{e.Before.Name}` to `{e.After.Name}`";
else if (e.Before.AvatarUrl != e.After.AvatarUrl)
str += $"Avatar url changed from `{e.Before.AvatarUrl}` to `{e.After.AvatarUrl}`";
else if (e.Before.Status != e.After.Status)
str += $"Status changed from `{e.Before.AvatarUrl}` to `{e.After.AvatarUrl}`";
}
public override void Init(CommandGroupBuilder cgb) {
cgb.CreateCommand(".logserver")
.Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. BOT OWNER ONLY. SERVER OWNER ONLY.")
.Do(DoFunc());
}
}
}

View File

@ -20,6 +20,7 @@ namespace NadekoBot.Modules {
class Administration : DiscordModule { class Administration : DiscordModule {
public Administration() : base() { public Administration() : base() {
commands.Add(new ServerGreetCommand()); commands.Add(new ServerGreetCommand());
commands.Add(new LogCommand());
} }
public override void Install(ModuleManager manager) { public override void Install(ModuleManager manager) {
@ -161,14 +162,14 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(".modules") cgb.CreateCommand(".modules")
.Description("List all bot modules") .Description("List all bot modules")
.Do(async e => { .Do(async e => {
await e.Send("`List of modules:` \n• " + string.Join("\n• ", NadekoBot.client.Modules().Modules.Select(m => m.Name))); await e.Send("`List of modules:` \n• " + string.Join("\n• ", NadekoBot.client.GetService<ModuleService>().Modules.Select(m => m.Name)));
}); });
cgb.CreateCommand(".commands") cgb.CreateCommand(".commands")
.Description("List all of the bot's commands from a certain module.") .Description("List all of the bot's commands from a certain module.")
.Parameter("module", ParameterType.Unparsed) .Parameter("module", ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
var commands = NadekoBot.client.Services.Get<CommandService>().AllCommands var commands = NadekoBot.client.GetService<CommandService>().AllCommands
.Where(c => c.Category.ToLower() == e.GetArg("module").Trim().ToLower()); .Where(c => c.Category.ToLower() == e.GetArg("module").Trim().ToLower());
if (commands == null || commands.Count() == 0) { if (commands == null || commands.Count() == 0) {
await e.Send("That module does not exist."); await e.Send("That module does not exist.");
@ -430,12 +431,25 @@ namespace NadekoBot.Modules {
ConcurrentDictionary<Server, bool> clearDictionary = new ConcurrentDictionary<Server, bool>(); ConcurrentDictionary<Server, bool> clearDictionary = new ConcurrentDictionary<Server, bool>();
cgb.CreateCommand(".clr") cgb.CreateCommand(".clr")
.Description("Clears some of nadeko's messages from the current channel.") .Description("Clears some of nadeko's (or some other user's if supplied) messages from the current channel.\n**Usage**: .clr @X")
.Parameter("user",ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
var usrId = NadekoBot.client.CurrentUser.Id;
if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) {
var usr = e.Server.FindUsers(e.GetArg("user")).FirstOrDefault();
if (usr != null)
usrId = usr.Id;
}
await Task.Run(async () => { await Task.Run(async () => {
var msgs = (await e.Channel.DownloadMessages(100)).Where(m => m.User.Id == NadekoBot.client.CurrentUser.Id); var msgs = (await e.Channel.DownloadMessages(100)).Where(m => m.User.Id == usrId);
foreach (var m in msgs) foreach (var m in msgs) {
try {
await m.Delete(); await m.Delete();
}
catch { }
await Task.Delay(200);
}
}); });
}); });
@ -629,6 +643,26 @@ namespace NadekoBot.Modules {
Console.WriteLine("---------------\nInner error:\n" + ex.InnerException); Console.WriteLine("---------------\nInner error:\n" + ex.InnerException);
} }
}); });
cgb.CreateCommand(".videocall")
.Description("Creates a private appear.in video call link for you and other mentioned people and sends it in private messages")
.Parameter("arg", ParameterType.Unparsed)
.Do(async e => {
try {
string str = "http://appear.in/";
var allUsrs = e.Message.MentionedUsers.Union(new User[] { e.User });
foreach (var usr in allUsrs) {
str += Uri.EscapeUriString(usr.Name[0].ToString());
}
str += new Random().Next(100000, 1000000);
foreach (var usr in allUsrs) {
await usr.SendMessage(str);
}
}
catch (Exception ex) {
Console.WriteLine(ex);
}
});
}); });
} }

View File

@ -349,7 +349,7 @@ namespace NadekoBot.Modules {
try { try {
bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
foreach (var module in NadekoBot.client.Modules().Modules) { foreach (var module in NadekoBot.client.GetService<ModuleService>().Modules) {
PermsHandler.SetServerModulePermission(e.Server, module.Name, state); PermsHandler.SetServerModulePermission(e.Server, module.Name, state);
} }
await e.Send($"All modules have been **{(state ? "enabled" : "disabled")}** on this server."); await e.Send($"All modules have been **{(state ? "enabled" : "disabled")}** on this server.");
@ -371,7 +371,7 @@ namespace NadekoBot.Modules {
bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
string module = PermissionHelper.ValidateModule(e.GetArg("module")); string module = PermissionHelper.ValidateModule(e.GetArg("module"));
foreach (var command in NadekoBot.client.Services.Get<CommandService>().AllCommands.Where(c => c.Category == module)) { foreach (var command in NadekoBot.client.GetService<CommandService>().AllCommands.Where(c => c.Category == module)) {
PermsHandler.SetServerCommandPermission(e.Server, command.Text, state); PermsHandler.SetServerCommandPermission(e.Server, command.Text, state);
} }
await e.Send($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** on this server."); await e.Send($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** on this server.");
@ -392,7 +392,7 @@ namespace NadekoBot.Modules {
try { try {
bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
Discord.Channel channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); Discord.Channel channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
foreach (var module in NadekoBot.client.Modules().Modules) { foreach (var module in NadekoBot.client.GetService<ModuleService>().Modules) {
PermsHandler.SetChannelModulePermission(channel, module.Name, state); PermsHandler.SetChannelModulePermission(channel, module.Name, state);
} }
@ -416,7 +416,7 @@ namespace NadekoBot.Modules {
bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
string module = PermissionHelper.ValidateModule(e.GetArg("module")); string module = PermissionHelper.ValidateModule(e.GetArg("module"));
Discord.Channel channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); Discord.Channel channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
foreach (var command in NadekoBot.client.Services.Get<CommandService>().AllCommands.Where(c => c.Category == module)) { foreach (var command in NadekoBot.client.GetService<CommandService>().AllCommands.Where(c => c.Category == module)) {
PermsHandler.SetChannelCommandPermission(channel, command.Text, state); PermsHandler.SetChannelCommandPermission(channel, command.Text, state);
} }
await e.Send($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel."); await e.Send($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
@ -437,7 +437,7 @@ namespace NadekoBot.Modules {
try { try {
bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
Discord.Role role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); Discord.Role role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
foreach (var module in NadekoBot.client.Modules().Modules) { foreach (var module in NadekoBot.client.GetService<ModuleService>().Modules) {
PermsHandler.SetRoleModulePermission(role, module.Name, state); PermsHandler.SetRoleModulePermission(role, module.Name, state);
} }
@ -461,7 +461,7 @@ namespace NadekoBot.Modules {
bool state = PermissionHelper.ValidateBool(e.GetArg("bool")); bool state = PermissionHelper.ValidateBool(e.GetArg("bool"));
string module = PermissionHelper.ValidateModule(e.GetArg("module")); string module = PermissionHelper.ValidateModule(e.GetArg("module"));
Discord.Role role = PermissionHelper.ValidateRole(e.Server, e.GetArg("channel")); Discord.Role role = PermissionHelper.ValidateRole(e.Server, e.GetArg("channel"));
foreach (var command in NadekoBot.client.Services.Get<CommandService>().AllCommands.Where(c => c.Category == module)) { foreach (var command in NadekoBot.client.GetService<CommandService>().AllCommands.Where(c => c.Category == module)) {
PermsHandler.SetRoleCommandPermission(role, command.Text, state); PermsHandler.SetRoleCommandPermission(role, command.Text, state);
} }
await e.Send($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role."); await e.Send($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");

View File

@ -62,7 +62,7 @@ namespace NadekoBot {
//create new discord client //create new discord client
client = new DiscordClient(new DiscordConfigBuilder() { client = new DiscordClient(new DiscordConfigBuilder() {
MessageCacheSize = 0, MessageCacheSize = 20,
ConnectionTimeout = 60000, ConnectionTimeout = 60000,
}); });
@ -77,13 +77,13 @@ namespace NadekoBot {
client.MessageReceived += Client_MessageReceived; client.MessageReceived += Client_MessageReceived;
//add command service //add command service
var commands = client.Services.Add<CommandService>(commandService); var commands = client.AddService<CommandService>(commandService);
//create module service //create module service
var modules = client.Services.Add<ModuleService>(new ModuleService()); var modules = client.AddService<ModuleService>(new ModuleService());
//add audio service //add audio service
var audio = client.Services.Add<AudioService>(new AudioService(new AudioServiceConfigBuilder() { var audio = client.AddService<AudioService>(new AudioService(new AudioServiceConfigBuilder() {
Channels = 2, Channels = 2,
EnableEncryption = false, EnableEncryption = false,
EnableMultiserver = true, EnableMultiserver = true,

View File

@ -146,6 +146,7 @@
<Compile Include="Classes\_DataModels\StatsModel.cs" /> <Compile Include="Classes\_DataModels\StatsModel.cs" />
<Compile Include="Classes\_DataModels\TypingArticleModel.cs" /> <Compile Include="Classes\_DataModels\TypingArticleModel.cs" />
<Compile Include="Commands\ClashOfClans.cs" /> <Compile Include="Commands\ClashOfClans.cs" />
<Compile Include="Commands\LogCommand.cs" />
<Compile Include="Commands\TriviaCommand.cs" /> <Compile Include="Commands\TriviaCommand.cs" />
<Compile Include="Classes\Trivia\TriviaGame.cs" /> <Compile Include="Classes\Trivia\TriviaGame.cs" />
<Compile Include="Classes\Trivia\TriviaQuestion.cs" /> <Compile Include="Classes\Trivia\TriviaQuestion.cs" />

Binary file not shown.