Currency name and sign should be external now!

This commit is contained in:
Master Kwoth 2016-03-28 04:36:59 +02:00
parent 6ee896d691
commit d72c809ae4
8 changed files with 586 additions and 309 deletions

View File

@ -20,7 +20,7 @@ namespace NadekoBot.Classes
var flows = ""; var flows = "";
for (var i = 0; i < amount; i++) for (var i = 0; i < amount; i++)
{ {
flows += "🌸"; flows += NadekoBot.Config.CurrencySign;
} }
await u.SendMessage("👑Congratulations!👑\nYou received: " + flows); await u.SendMessage("👑Congratulations!👑\nYou received: " + flows);
} }

View File

@ -1,11 +1,12 @@
using System; using Discord;
using Newtonsoft.Json;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Discord;
using Newtonsoft.Json;
namespace NadekoBot.Classes.JSONModels { namespace NadekoBot.Classes.JSONModels
public class Configuration { {
public class Configuration
{
public bool DontJoinServers { get; set; } = false; public bool DontJoinServers { get; set; } = false;
public bool ForwardMessages { get; set; } = true; public bool ForwardMessages { get; set; } = true;
public bool IsRotatingStatus { get; set; } = false; public bool IsRotatingStatus { get; set; } = false;
@ -49,7 +50,7 @@ namespace NadekoBot.Classes.JSONModels {
"NO - It may cause disease contraction" "NO - It may cause disease contraction"
}; };
public string[] DisguiseResponses { get; set; } = { public string[] DisguiseResponses { get; set; } = {
"https://cdn.discordapp.com/attachments/140007341880901632/156721710458994690/Cc5mixjUYAADgBs.jpg", "https://cdn.discordapp.com/attachments/140007341880901632/156721710458994690/Cc5mixjUYAADgBs.jpg",
"https://cdn.discordapp.com/attachments/140007341880901632/156721715831898113/hqdefault.jpg", "https://cdn.discordapp.com/attachments/140007341880901632/156721715831898113/hqdefault.jpg",
"https://cdn.discordapp.com/attachments/140007341880901632/156721724430352385/okawari_01_haruka_weird_mask.jpg", "https://cdn.discordapp.com/attachments/140007341880901632/156721724430352385/okawari_01_haruka_weird_mask.jpg",
@ -74,9 +75,13 @@ namespace NadekoBot.Classes.JSONModels {
"http://gallery1.anivide.com/_full/65030_1382582341.gif", "http://gallery1.anivide.com/_full/65030_1382582341.gif",
"https://49.media.tumblr.com/8e8a099c4eba22abd3ec0f70fd087cce/tumblr_nxovj9oY861ur1mffo1_500.gif ", "https://49.media.tumblr.com/8e8a099c4eba22abd3ec0f70fd087cce/tumblr_nxovj9oY861ur1mffo1_500.gif ",
}; };
public string CurrencySign { get; set; } = "🌸";
public string CurrencyName { get; set; } = "NadekoFlower";
} }
public class CommandPrefixesModel { public class CommandPrefixesModel
{
public string Administration { get; set; } = "."; public string Administration { get; set; } = ".";
public string Searches { get; set; } = "~"; public string Searches { get; set; } = "~";
public string NSFW { get; set; } = "~"; public string NSFW { get; set; } = "~";
@ -91,10 +96,13 @@ namespace NadekoBot.Classes.JSONModels {
public string Programming { get; set; } = "%"; public string Programming { get; set; } = "%";
} }
public static class ConfigHandler { public static class ConfigHandler
{
private static readonly object configLock = new object(); private static readonly object configLock = new object();
public static void SaveConfig() { public static void SaveConfig()
lock (configLock) { {
lock (configLock)
{
File.WriteAllText("data/config.json", JsonConvert.SerializeObject(NadekoBot.Config, Formatting.Indented)); File.WriteAllText("data/config.json", JsonConvert.SerializeObject(NadekoBot.Config, Formatting.Indented));
} }
} }
@ -110,7 +118,8 @@ namespace NadekoBot.Classes.JSONModels {
public static bool IsUserBlacklisted(ulong id) => NadekoBot.Config.UserBlacklist.Contains(id); public static bool IsUserBlacklisted(ulong id) => NadekoBot.Config.UserBlacklist.Contains(id);
} }
public class Quote { public class Quote
{
public string Author { get; set; } public string Author { get; set; }
public string Text { get; set; } public string Text { get; set; }

View File

@ -1,23 +1,24 @@
using System; using Discord;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;
using System.Timers;
using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;
using Discord;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Classes.Permissions; using NadekoBot.Classes.Permissions;
using NadekoBot.Modules; using NadekoBot.Modules;
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
namespace NadekoBot.Commands { namespace NadekoBot.Commands
internal class LogCommand : DiscordCommand { {
internal class LogCommand : DiscordCommand
{
private readonly ConcurrentDictionary<Server, Channel> logs = new ConcurrentDictionary<Server, Channel>(); private readonly ConcurrentDictionary<Server, Channel> logs = new ConcurrentDictionary<Server, Channel>();
private readonly ConcurrentDictionary<Server, Channel> loggingPresences = new ConcurrentDictionary<Server, Channel>(); private readonly ConcurrentDictionary<Server, Channel> loggingPresences = new ConcurrentDictionary<Server, Channel>();
private readonly ConcurrentDictionary<Channel, Channel> voiceChannelLog = new ConcurrentDictionary<Channel, Channel>(); private readonly ConcurrentDictionary<Channel, Channel> voiceChannelLog = new ConcurrentDictionary<Channel, Channel>();
public LogCommand(DiscordModule module) : base(module) { public LogCommand(DiscordModule module) : base(module)
{
NadekoBot.Client.MessageReceived += MsgRecivd; NadekoBot.Client.MessageReceived += MsgRecivd;
NadekoBot.Client.MessageDeleted += MsgDltd; NadekoBot.Client.MessageDeleted += MsgDltd;
NadekoBot.Client.MessageUpdated += MsgUpdtd; NadekoBot.Client.MessageUpdated += MsgUpdtd;
@ -25,11 +26,13 @@ namespace NadekoBot.Commands {
NadekoBot.Client.UserBanned += UsrBanned; NadekoBot.Client.UserBanned += UsrBanned;
NadekoBot.Client.MessageReceived += async (s, e) => { NadekoBot.Client.MessageReceived += async (s, e) =>
{
if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) if (e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id)
return; return;
if (!SpecificConfigurations.Default.Of(e.Server.Id).SendPrivateMessageOnMention) return; if (!SpecificConfigurations.Default.Of(e.Server.Id).SendPrivateMessageOnMention) return;
try { try
{
var usr = e.Message.MentionedUsers.FirstOrDefault(u => u != e.User); var usr = e.Message.MentionedUsers.FirstOrDefault(u => u != e.User);
if (usr?.Status != UserStatus.Offline) if (usr?.Status != UserStatus.Offline)
return; return;
@ -38,22 +41,28 @@ namespace NadekoBot.Commands {
$"User `{e.User.Name}` mentioned you on " + $"User `{e.User.Name}` mentioned you on " +
$"`{e.Server.Name}` server while you were offline.\n" + $"`{e.Server.Name}` server while you were offline.\n" +
$"`Message:` {e.Message.Text}"); $"`Message:` {e.Message.Text}");
} catch { } }
catch { }
}; };
} }
private async void UsrBanned(object sender, UserEventArgs e) { private async void UsrBanned(object sender, UserEventArgs e)
try { {
try
{
Channel ch; Channel ch;
if (!logs.TryGetValue(e.Server, out ch)) if (!logs.TryGetValue(e.Server, out ch))
return; return;
await ch.SendMessage($"`User banned:` **{e.User.Name}** ({e.User.Id})"); await ch.SendMessage($"`User banned:` **{e.User.Name}** ({e.User.Id})");
} catch { } }
catch { }
} }
public Func<CommandEventArgs, Task> DoFunc() => async e => { public Func<CommandEventArgs, Task> DoFunc() => async e =>
{
Channel ch; Channel ch;
if (!logs.TryRemove(e.Server, out ch)) { if (!logs.TryRemove(e.Server, out ch))
{
logs.TryAdd(e.Server, e.Channel); logs.TryAdd(e.Server, e.Channel);
await e.Channel.SendMessage($"**I WILL BEGIN LOGGING SERVER ACTIVITY IN THIS CHANNEL**"); await e.Channel.SendMessage($"**I WILL BEGIN LOGGING SERVER ACTIVITY IN THIS CHANNEL**");
return; return;
@ -62,57 +71,75 @@ namespace NadekoBot.Commands {
await e.Channel.SendMessage($"**NO LONGER LOGGING IN {ch.Mention} CHANNEL**"); await e.Channel.SendMessage($"**NO LONGER LOGGING IN {ch.Mention} CHANNEL**");
}; };
private async void MsgRecivd(object sender, MessageEventArgs e) { private async void MsgRecivd(object sender, MessageEventArgs e)
try { {
try
{
if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id)
return; return;
Channel ch; Channel ch;
if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch) if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch)
return; return;
await ch.SendMessage($"`Type:` **Message received** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n`{e.User}:` {e.Message.Text}"); await ch.SendMessage($"`Type:` **Message received** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n`{e.User}:` {e.Message.Text}");
} catch { } }
catch { }
} }
private async void MsgDltd(object sender, MessageEventArgs e) { private async void MsgDltd(object sender, MessageEventArgs e)
try { {
try
{
if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id)
return; return;
Channel ch; Channel ch;
if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch) if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch)
return; return;
await ch.SendMessage($"`Type:` **Message deleted** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n`{e.User}:` {e.Message.Text}"); await ch.SendMessage($"`Type:` **Message deleted** `Time:` **{DateTime.Now}** `Channel:` **{e.Channel.Name}**\n`{e.User}:` {e.Message.Text}");
} catch { } }
catch { }
} }
private async void MsgUpdtd(object sender, MessageUpdatedEventArgs e) { private async void MsgUpdtd(object sender, MessageUpdatedEventArgs e)
try { {
try
{
if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id) if (e.Server == null || e.Channel.IsPrivate || e.User.Id == NadekoBot.Client.CurrentUser.Id)
return; return;
Channel ch; Channel ch;
if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch) if (!logs.TryGetValue(e.Server, out ch) || e.Channel == ch)
return; 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.After.Text}"); 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.After.Text}");
} catch { } }
catch { }
} }
private async void UsrUpdtd(object sender, UserUpdatedEventArgs e) { private async void UsrUpdtd(object sender, UserUpdatedEventArgs e)
try { {
try
{
Channel ch; Channel ch;
if (loggingPresences.TryGetValue(e.Server, out ch)) if (loggingPresences.TryGetValue(e.Server, out ch))
if (e.Before.Status != e.After.Status) { if (e.Before.Status != e.After.Status)
{
await ch.SendMessage($"**{e.Before.Name}** is now **{e.After.Status}**."); await ch.SendMessage($"**{e.Before.Name}** is now **{e.After.Status}**.");
} }
} catch { } }
catch { }
try { try
if (e.Before.VoiceChannel != null && voiceChannelLog.ContainsKey(e.Before.VoiceChannel)) { {
if (e.Before.VoiceChannel != null && voiceChannelLog.ContainsKey(e.Before.VoiceChannel))
{
if (e.After.VoiceChannel != e.Before.VoiceChannel) if (e.After.VoiceChannel != e.Before.VoiceChannel)
await voiceChannelLog[e.Before.VoiceChannel].SendMessage($"🎼`{e.Before.Name} has left the` {e.Before.VoiceChannel.Mention} `voice channel.`"); await voiceChannelLog[e.Before.VoiceChannel].SendMessage($"🎼`{e.Before.Name} has left the` {e.Before.VoiceChannel.Mention} `voice channel.`");
} }
if (e.After.VoiceChannel != null && voiceChannelLog.ContainsKey(e.After.VoiceChannel)) { if (e.After.VoiceChannel != null && voiceChannelLog.ContainsKey(e.After.VoiceChannel))
{
if (e.After.VoiceChannel != e.Before.VoiceChannel) if (e.After.VoiceChannel != e.Before.VoiceChannel)
await voiceChannelLog[e.After.VoiceChannel].SendMessage($"🎼`{e.After.Name} has joined the`{e.After.VoiceChannel.Mention} `voice channel.`"); await voiceChannelLog[e.After.VoiceChannel].SendMessage($"🎼`{e.After.Name} has joined the`{e.After.VoiceChannel.Mention} `voice channel.`");
} }
} catch { } }
catch { }
try { try
{
Channel ch; Channel ch;
if (!logs.TryGetValue(e.Server, out ch)) if (!logs.TryGetValue(e.Server, out ch))
return; return;
@ -126,15 +153,18 @@ namespace NadekoBot.Commands {
else else
return; return;
await ch.SendMessage(str); await ch.SendMessage(str);
} catch { } }
catch { }
} }
internal override void Init(CommandGroupBuilder cgb) { internal override void Init(CommandGroupBuilder cgb)
{
cgb.CreateCommand(Module.Prefix + "spmom") cgb.CreateCommand(Module.Prefix + "spmom")
.Description("Toggles whether mentions of other offline users on your server will send a pm to them.") .Description("Toggles whether mentions of other offline users on your server will send a pm to them.")
.AddCheck(SimpleCheckers.ManageServer()) .AddCheck(SimpleCheckers.ManageServer())
.Do(async e => { .Do(async e =>
{
var specificConfig = SpecificConfigurations.Default.Of(e.Server.Id); var specificConfig = SpecificConfigurations.Default.Of(e.Server.Id);
specificConfig.SendPrivateMessageOnMention = specificConfig.SendPrivateMessageOnMention =
!specificConfig.SendPrivateMessageOnMention; !specificConfig.SendPrivateMessageOnMention;
@ -156,9 +186,11 @@ namespace NadekoBot.Commands {
.Description("Starts logging to this channel when someone from the server goes online/offline/idle. **Owner Only!**") .Description("Starts logging to this channel when someone from the server goes online/offline/idle. **Owner Only!**")
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.AddCheck(SimpleCheckers.ManageServer()) .AddCheck(SimpleCheckers.ManageServer())
.Do(async e => { .Do(async e =>
{
Channel ch; Channel ch;
if (!loggingPresences.TryRemove(e.Server, out ch)) { if (!loggingPresences.TryRemove(e.Server, out ch))
{
loggingPresences.TryAdd(e.Server, e.Channel); loggingPresences.TryAdd(e.Server, e.Channel);
await e.Channel.SendMessage($"**User presence notifications enabled.**"); await e.Channel.SendMessage($"**User presence notifications enabled.**");
return; return;
@ -172,25 +204,31 @@ namespace NadekoBot.Commands {
.Parameter("all", ParameterType.Optional) .Parameter("all", ParameterType.Optional)
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.AddCheck(SimpleCheckers.ManageServer()) .AddCheck(SimpleCheckers.ManageServer())
.Do(async e => { .Do(async e =>
{
if (e.GetArg("all")?.ToLower() == "all") { if (e.GetArg("all")?.ToLower() == "all")
foreach (var voiceChannel in e.Server.VoiceChannels) { {
foreach (var voiceChannel in e.Server.VoiceChannels)
{
voiceChannelLog.TryAdd(voiceChannel, e.Channel); voiceChannelLog.TryAdd(voiceChannel, e.Channel);
} }
await e.Channel.SendMessage("Started logging user presence for **ALL** voice channels!"); await e.Channel.SendMessage("Started logging user presence for **ALL** voice channels!");
return; return;
} }
if (e.User.VoiceChannel == null) { if (e.User.VoiceChannel == null)
{
await e.Channel.SendMessage("💢 You are not in a voice channel right now. If you are, please rejoin it."); await e.Channel.SendMessage("💢 You are not in a voice channel right now. If you are, please rejoin it.");
return; return;
} }
Channel throwaway; Channel throwaway;
if (!voiceChannelLog.TryRemove(e.User.VoiceChannel, out throwaway)) { if (!voiceChannelLog.TryRemove(e.User.VoiceChannel, out throwaway))
{
voiceChannelLog.TryAdd(e.User.VoiceChannel, e.Channel); voiceChannelLog.TryAdd(e.User.VoiceChannel, e.Channel);
await e.Channel.SendMessage($"`Logging user updates for` {e.User.VoiceChannel.Mention} `voice channel.`"); await e.Channel.SendMessage($"`Logging user updates for` {e.User.VoiceChannel.Mention} `voice channel.`");
} else }
else
await e.Channel.SendMessage($"`Stopped logging user updates for` {e.User.VoiceChannel.Mention} `voice channel.`"); await e.Channel.SendMessage($"`Stopped logging user updates for` {e.User.VoiceChannel.Mention} `voice channel.`");
}); });
} }

View File

@ -1,21 +1,23 @@
using Discord.Modules;
using Discord.Commands;
using Discord; using Discord;
using System; using Discord.Commands;
using System.Collections.Generic; using Discord.Modules;
using System.Linq;
using NadekoBot.Extensions;
using System.Threading.Tasks;
using NadekoBot.Commands;
using System.IO;
using Newtonsoft.Json.Linq;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Classes.Permissions;
using NadekoBot.Classes._DataModels; using NadekoBot.Classes._DataModels;
using NadekoBot.Classes.Permissions;
using NadekoBot.Commands;
using NadekoBot.Extensions;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace NadekoBot.Modules { namespace NadekoBot.Modules
internal class Administration : DiscordModule { {
public Administration() { internal class Administration : DiscordModule
{
public Administration()
{
commands.Add(new ServerGreetCommand(this)); commands.Add(new ServerGreetCommand(this));
commands.Add(new LogCommand(this)); commands.Add(new LogCommand(this));
commands.Add(new MessageRepeater(this)); commands.Add(new MessageRepeater(this));
@ -28,8 +30,10 @@ namespace NadekoBot.Modules {
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration; public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration;
public override void Install(ModuleManager manager) { public override void Install(ModuleManager manager)
manager.CreateCommands("", cgb => { {
manager.CreateCommands("", cgb =>
{
cgb.AddCheck(PermissionChecker.Instance); cgb.AddCheck(PermissionChecker.Instance);
@ -42,32 +46,39 @@ namespace NadekoBot.Modules {
.Parameter("user_name", ParameterType.Required) .Parameter("user_name", ParameterType.Required)
.Parameter("role_name", ParameterType.Unparsed) .Parameter("role_name", ParameterType.Unparsed)
.AddCheck(SimpleCheckers.CanManageRoles) .AddCheck(SimpleCheckers.CanManageRoles)
.Do(async e => { .Do(async e =>
{
var userName = e.GetArg("user_name"); var userName = e.GetArg("user_name");
var roleName = e.GetArg("role_name"); var roleName = e.GetArg("role_name");
if (string.IsNullOrWhiteSpace(roleName)) return; if (string.IsNullOrWhiteSpace(roleName)) return;
if (!e.User.ServerPermissions.ManageRoles) { if (!e.User.ServerPermissions.ManageRoles)
{
await e.Channel.SendMessage("You have insufficient permissions."); await e.Channel.SendMessage("You have insufficient permissions.");
} }
var usr = e.Server.FindUsers(userName).FirstOrDefault(); var usr = e.Server.FindUsers(userName).FirstOrDefault();
if (usr == null) { if (usr == null)
{
await e.Channel.SendMessage("You failed to supply a valid username"); await e.Channel.SendMessage("You failed to supply a valid username");
return; return;
} }
var role = e.Server.FindRoles(roleName).FirstOrDefault(); var role = e.Server.FindRoles(roleName).FirstOrDefault();
if (role == null) { if (role == null)
{
await e.Channel.SendMessage("You failed to supply a valid role"); await e.Channel.SendMessage("You failed to supply a valid role");
return; return;
} }
try { try
{
await usr.AddRoles(role); await usr.AddRoles(role);
await e.Channel.SendMessage($"Successfully added role **{role.Name}** to user **{usr.Name}**"); await e.Channel.SendMessage($"Successfully added role **{role.Name}** to user **{usr.Name}**");
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Failed to add roles. Bot has insufficient permissions.\n"); await e.Channel.SendMessage("Failed to add roles. Bot has insufficient permissions.\n");
Console.WriteLine(ex.ToString()); Console.WriteLine(ex.ToString());
} }
@ -78,28 +89,34 @@ namespace NadekoBot.Modules {
.Parameter("user_name", ParameterType.Required) .Parameter("user_name", ParameterType.Required)
.Parameter("role_name", ParameterType.Unparsed) .Parameter("role_name", ParameterType.Unparsed)
.AddCheck(SimpleCheckers.CanManageRoles) .AddCheck(SimpleCheckers.CanManageRoles)
.Do(async e => { .Do(async e =>
{
var userName = e.GetArg("user_name"); var userName = e.GetArg("user_name");
var roleName = e.GetArg("role_name"); var roleName = e.GetArg("role_name");
if (string.IsNullOrWhiteSpace(roleName)) return; if (string.IsNullOrWhiteSpace(roleName)) return;
var usr = e.Server.FindUsers(userName).FirstOrDefault(); var usr = e.Server.FindUsers(userName).FirstOrDefault();
if (usr == null) { if (usr == null)
{
await e.Channel.SendMessage("You failed to supply a valid username"); await e.Channel.SendMessage("You failed to supply a valid username");
return; return;
} }
var role = e.Server.FindRoles(roleName).FirstOrDefault(); var role = e.Server.FindRoles(roleName).FirstOrDefault();
if (role == null) { if (role == null)
{
await e.Channel.SendMessage("You failed to supply a valid role"); await e.Channel.SendMessage("You failed to supply a valid role");
return; return;
} }
try { try
{
await usr.RemoveRoles(role); await usr.RemoveRoles(role);
await e.Channel.SendMessage($"Successfully removed role **{role.Name}** from user **{usr.Name}**"); await e.Channel.SendMessage($"Successfully removed role **{role.Name}** from user **{usr.Name}**");
} catch { }
catch
{
await e.Channel.SendMessage("Failed to remove roles. Most likely reason: Insufficient permissions."); await e.Channel.SendMessage("Failed to remove roles. Most likely reason: Insufficient permissions.");
} }
}); });
@ -108,13 +125,17 @@ namespace NadekoBot.Modules {
.Description("Creates a role with a given name.**Usage**: .r Awesome Role") .Description("Creates a role with a given name.**Usage**: .r Awesome Role")
.Parameter("role_name", ParameterType.Unparsed) .Parameter("role_name", ParameterType.Unparsed)
.AddCheck(SimpleCheckers.CanManageRoles) .AddCheck(SimpleCheckers.CanManageRoles)
.Do(async e => { .Do(async e =>
{
if (string.IsNullOrWhiteSpace(e.GetArg("role_name"))) if (string.IsNullOrWhiteSpace(e.GetArg("role_name")))
return; return;
try { try
{
var r = await e.Server.CreateRole(e.GetArg("role_name")); var r = await e.Server.CreateRole(e.GetArg("role_name"));
await e.Channel.SendMessage($"Successfully created role **{r.Name}**."); await e.Channel.SendMessage($"Successfully created role **{r.Name}**.");
} catch (Exception) { }
catch (Exception)
{
await e.Channel.SendMessage(":warning: Unspecified error."); await e.Channel.SendMessage(":warning: Unspecified error.");
} }
}); });
@ -125,26 +146,31 @@ namespace NadekoBot.Modules {
.Parameter("g", ParameterType.Optional) .Parameter("g", ParameterType.Optional)
.Parameter("b", ParameterType.Optional) .Parameter("b", ParameterType.Optional)
.Description("Set a role's color to the hex or 0-255 rgb color value provided.\n**Usage**: .color Admin 255 200 100 or .color Admin ffba55") .Description("Set a role's color to the hex or 0-255 rgb color value provided.\n**Usage**: .color Admin 255 200 100 or .color Admin ffba55")
.Do(async e => { .Do(async e =>
if (!e.User.ServerPermissions.ManageRoles) { {
if (!e.User.ServerPermissions.ManageRoles)
{
await e.Channel.SendMessage("You don't have permission to use this!"); await e.Channel.SendMessage("You don't have permission to use this!");
return; return;
} }
var args = e.Args.Where(s => s != string.Empty); var args = e.Args.Where(s => s != string.Empty);
if (args.Count() != 2 && args.Count() != 4) { if (args.Count() != 2 && args.Count() != 4)
{
await e.Channel.SendMessage("The parameters are invalid."); await e.Channel.SendMessage("The parameters are invalid.");
return; return;
} }
var role = e.Server.FindRoles(e.Args[0]).FirstOrDefault(); var role = e.Server.FindRoles(e.Args[0]).FirstOrDefault();
if (role == null) { if (role == null)
{
await e.Channel.SendMessage("That role does not exist."); await e.Channel.SendMessage("That role does not exist.");
return; return;
} }
try { try
{
var rgb = args.Count() == 4; var rgb = args.Count() == 4;
var red = Convert.ToByte(rgb ? int.Parse(e.Args[1]) : Convert.ToInt32(e.Args[1].Substring(0, 2), 16)); var red = Convert.ToByte(rgb ? int.Parse(e.Args[1]) : Convert.ToInt32(e.Args[1].Substring(0, 2), 16));
@ -153,7 +179,9 @@ namespace NadekoBot.Modules {
await role.Edit(color: new Color(red, green, blue)); await role.Edit(color: new Color(red, green, blue));
await e.Channel.SendMessage($"Role {role.Name}'s color has been changed."); await e.Channel.SendMessage($"Role {role.Name}'s color has been changed.");
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Error occured, most likely invalid parameters or insufficient permissions."); await e.Channel.SendMessage("Error occured, most likely invalid parameters or insufficient permissions.");
} }
}); });
@ -161,8 +189,10 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "roles") cgb.CreateCommand(Prefix + "roles")
.Description("List all roles on this server or a single user if specified.") .Description("List all roles on this server or a single user if specified.")
.Parameter("user", ParameterType.Unparsed) .Parameter("user", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) { {
if (!string.IsNullOrWhiteSpace(e.GetArg("user")))
{
var usr = e.Server.FindUsers(e.GetArg("user")).FirstOrDefault(); var usr = e.Server.FindUsers(e.GetArg("user")).FirstOrDefault();
if (usr == null) return; if (usr == null) return;
@ -176,24 +206,31 @@ namespace NadekoBot.Modules {
.Parameter("user", ParameterType.Required) .Parameter("user", ParameterType.Required)
.Parameter("msg", ParameterType.Optional) .Parameter("msg", ParameterType.Optional)
.Description("Bans a user by id or name with an optional message.\n**Usage**: .b \"@some Guy\" Your behaviour is toxic.") .Description("Bans a user by id or name with an optional message.\n**Usage**: .b \"@some Guy\" Your behaviour is toxic.")
.Do(async e => { .Do(async e =>
{
var msg = e.GetArg("msg"); var msg = e.GetArg("msg");
var user = e.GetArg("user"); var user = e.GetArg("user");
if (e.User.ServerPermissions.BanMembers) { if (e.User.ServerPermissions.BanMembers)
{
var usr = e.Server.FindUsers(user).FirstOrDefault(); var usr = e.Server.FindUsers(user).FirstOrDefault();
if (usr == null) { if (usr == null)
{
await e.Channel.SendMessage("User not found."); await e.Channel.SendMessage("User not found.");
return; return;
} }
if (!string.IsNullOrWhiteSpace(msg)) { if (!string.IsNullOrWhiteSpace(msg))
{
await usr.SendMessage($"**You have been BANNED from `{e.Server.Name}` server.**\n" + await usr.SendMessage($"**You have been BANNED from `{e.Server.Name}` server.**\n" +
$"Reason: {msg}"); $"Reason: {msg}");
await Task.Delay(2000); // temp solution; give time for a message to be send, fu volt await Task.Delay(2000); // temp solution; give time for a message to be send, fu volt
} }
try { try
{
await e.Server.Ban(usr); await e.Server.Ban(usr);
await e.Channel.SendMessage("Banned user " + usr.Name + " Id: " + usr.Id); await e.Channel.SendMessage("Banned user " + usr.Name + " Id: " + usr.Id);
} catch { }
catch
{
await e.Channel.SendMessage("Error. Most likely I don't have sufficient permissions."); await e.Channel.SendMessage("Error. Most likely I don't have sufficient permissions.");
} }
} }
@ -203,24 +240,31 @@ namespace NadekoBot.Modules {
.Parameter("user") .Parameter("user")
.Parameter("msg", ParameterType.Unparsed) .Parameter("msg", ParameterType.Unparsed)
.Description("Kicks a mentioned user.") .Description("Kicks a mentioned user.")
.Do(async e => { .Do(async e =>
{
var msg = e.GetArg("msg"); var msg = e.GetArg("msg");
var user = e.GetArg("user"); var user = e.GetArg("user");
if (e.User.ServerPermissions.KickMembers) { if (e.User.ServerPermissions.KickMembers)
{
var usr = e.Server.FindUsers(user).FirstOrDefault(); var usr = e.Server.FindUsers(user).FirstOrDefault();
if (usr == null) { if (usr == null)
{
await e.Channel.SendMessage("User not found."); await e.Channel.SendMessage("User not found.");
return; return;
} }
if (!string.IsNullOrWhiteSpace(msg)) { if (!string.IsNullOrWhiteSpace(msg))
{
await usr.SendMessage($"**You have been KICKED from `{e.Server.Name}` server.**\n" + await usr.SendMessage($"**You have been KICKED from `{e.Server.Name}` server.**\n" +
$"Reason: {msg}"); $"Reason: {msg}");
await Task.Delay(2000); // temp solution; give time for a message to be send, fu volt await Task.Delay(2000); // temp solution; give time for a message to be send, fu volt
} }
try { try
{
await usr.Kick(); await usr.Kick();
await e.Channel.SendMessage("Kicked user " + usr.Name + " Id: " + usr.Id); await e.Channel.SendMessage("Kicked user " + usr.Name + " Id: " + usr.Id);
} catch { }
catch
{
await e.Channel.SendMessage("Error. Most likely I don't have sufficient permissions."); await e.Channel.SendMessage("Error. Most likely I don't have sufficient permissions.");
} }
} }
@ -228,19 +272,25 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "mute") cgb.CreateCommand(Prefix + "mute")
.Description("Mutes mentioned user or users.") .Description("Mutes mentioned user or users.")
.Parameter("throwaway", ParameterType.Unparsed) .Parameter("throwaway", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
if (!e.User.ServerPermissions.MuteMembers) { {
if (!e.User.ServerPermissions.MuteMembers)
{
await e.Channel.SendMessage("You do not have permission to do that."); await e.Channel.SendMessage("You do not have permission to do that.");
return; return;
} }
if (!e.Message.MentionedUsers.Any()) if (!e.Message.MentionedUsers.Any())
return; return;
try { try
foreach (var u in e.Message.MentionedUsers) { {
foreach (var u in e.Message.MentionedUsers)
{
await u.Edit(isMuted: true); await u.Edit(isMuted: true);
} }
await e.Channel.SendMessage("Mute successful"); await e.Channel.SendMessage("Mute successful");
} catch { }
catch
{
await e.Channel.SendMessage("I do not have permission to do that most likely."); await e.Channel.SendMessage("I do not have permission to do that most likely.");
} }
}); });
@ -248,19 +298,25 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "unmute") cgb.CreateCommand(Prefix + "unmute")
.Description("Unmutes mentioned user or users.") .Description("Unmutes mentioned user or users.")
.Parameter("throwaway", ParameterType.Unparsed) .Parameter("throwaway", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
if (!e.User.ServerPermissions.MuteMembers) { {
if (!e.User.ServerPermissions.MuteMembers)
{
await e.Channel.SendMessage("You do not have permission to do that."); await e.Channel.SendMessage("You do not have permission to do that.");
return; return;
} }
if (!e.Message.MentionedUsers.Any()) if (!e.Message.MentionedUsers.Any())
return; return;
try { try
foreach (var u in e.Message.MentionedUsers) { {
foreach (var u in e.Message.MentionedUsers)
{
await u.Edit(isMuted: false); await u.Edit(isMuted: false);
} }
await e.Channel.SendMessage("Unmute successful"); await e.Channel.SendMessage("Unmute successful");
} catch { }
catch
{
await e.Channel.SendMessage("I do not have permission to do that most likely."); await e.Channel.SendMessage("I do not have permission to do that most likely.");
} }
}); });
@ -269,19 +325,25 @@ namespace NadekoBot.Modules {
.Alias(Prefix + "deaf") .Alias(Prefix + "deaf")
.Description("Deafens mentioned user or users") .Description("Deafens mentioned user or users")
.Parameter("throwaway", ParameterType.Unparsed) .Parameter("throwaway", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
if (!e.User.ServerPermissions.DeafenMembers) { {
if (!e.User.ServerPermissions.DeafenMembers)
{
await e.Channel.SendMessage("You do not have permission to do that."); await e.Channel.SendMessage("You do not have permission to do that.");
return; return;
} }
if (!e.Message.MentionedUsers.Any()) if (!e.Message.MentionedUsers.Any())
return; return;
try { try
foreach (var u in e.Message.MentionedUsers) { {
foreach (var u in e.Message.MentionedUsers)
{
await u.Edit(isDeafened: true); await u.Edit(isDeafened: true);
} }
await e.Channel.SendMessage("Deafen successful"); await e.Channel.SendMessage("Deafen successful");
} catch { }
catch
{
await e.Channel.SendMessage("I do not have permission to do that most likely."); await e.Channel.SendMessage("I do not have permission to do that most likely.");
} }
}); });
@ -290,19 +352,25 @@ namespace NadekoBot.Modules {
.Alias(Prefix + "undeaf") .Alias(Prefix + "undeaf")
.Description("Undeafens mentioned user or users") .Description("Undeafens mentioned user or users")
.Parameter("throwaway", ParameterType.Unparsed) .Parameter("throwaway", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
if (!e.User.ServerPermissions.DeafenMembers) { {
if (!e.User.ServerPermissions.DeafenMembers)
{
await e.Channel.SendMessage("You do not have permission to do that."); await e.Channel.SendMessage("You do not have permission to do that.");
return; return;
} }
if (!e.Message.MentionedUsers.Any()) if (!e.Message.MentionedUsers.Any())
return; return;
try { try
foreach (var u in e.Message.MentionedUsers) { {
foreach (var u in e.Message.MentionedUsers)
{
await u.Edit(isDeafened: false); await u.Edit(isDeafened: false);
} }
await e.Channel.SendMessage("Undeafen successful"); await e.Channel.SendMessage("Undeafen successful");
} catch { }
catch
{
await e.Channel.SendMessage("I do not have permission to do that most likely."); await e.Channel.SendMessage("I do not have permission to do that most likely.");
} }
}); });
@ -310,13 +378,18 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "rvch") cgb.CreateCommand(Prefix + "rvch")
.Description("Removes a voice channel with a given name.") .Description("Removes a voice channel with a given name.")
.Parameter("channel_name", ParameterType.Required) .Parameter("channel_name", ParameterType.Required)
.Do(async e => { .Do(async e =>
try { {
if (e.User.ServerPermissions.ManageChannels) { try
{
if (e.User.ServerPermissions.ManageChannels)
{
await e.Server.FindChannels(e.GetArg("channel_name"), ChannelType.Voice).FirstOrDefault()?.Delete(); await e.Server.FindChannels(e.GetArg("channel_name"), ChannelType.Voice).FirstOrDefault()?.Delete();
await e.Channel.SendMessage($"Removed channel **{e.GetArg("channel_name")}**."); await e.Channel.SendMessage($"Removed channel **{e.GetArg("channel_name")}**.");
} }
} catch { }
catch
{
await e.Channel.SendMessage("Insufficient permissions."); await e.Channel.SendMessage("Insufficient permissions.");
} }
}); });
@ -324,13 +397,18 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "vch").Alias(Prefix + "cvch") cgb.CreateCommand(Prefix + "vch").Alias(Prefix + "cvch")
.Description("Creates a new voice channel with a given name.") .Description("Creates a new voice channel with a given name.")
.Parameter("channel_name", ParameterType.Required) .Parameter("channel_name", ParameterType.Required)
.Do(async e => { .Do(async e =>
try { {
if (e.User.ServerPermissions.ManageChannels) { try
{
if (e.User.ServerPermissions.ManageChannels)
{
await e.Server.CreateChannel(e.GetArg("channel_name"), ChannelType.Voice); await e.Server.CreateChannel(e.GetArg("channel_name"), ChannelType.Voice);
await e.Channel.SendMessage($"Created voice channel **{e.GetArg("channel_name")}**."); await e.Channel.SendMessage($"Created voice channel **{e.GetArg("channel_name")}**.");
} }
} catch { }
catch
{
await e.Channel.SendMessage("Insufficient permissions."); await e.Channel.SendMessage("Insufficient permissions.");
} }
}); });
@ -338,15 +416,20 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "rch").Alias(Prefix + "rtch") cgb.CreateCommand(Prefix + "rch").Alias(Prefix + "rtch")
.Description("Removes a text channel with a given name.") .Description("Removes a text channel with a given name.")
.Parameter("channel_name", ParameterType.Required) .Parameter("channel_name", ParameterType.Required)
.Do(async e => { .Do(async e =>
try { {
if (e.User.ServerPermissions.ManageChannels) { try
{
if (e.User.ServerPermissions.ManageChannels)
{
var channel = e.Server.FindChannels(e.GetArg("channel_name"), ChannelType.Text).FirstOrDefault(); var channel = e.Server.FindChannels(e.GetArg("channel_name"), ChannelType.Text).FirstOrDefault();
if (channel == null) return; if (channel == null) return;
await channel.Delete(); await channel.Delete();
await e.Channel.SendMessage($"Removed text channel **{e.GetArg("channel_name")}**."); await e.Channel.SendMessage($"Removed text channel **{e.GetArg("channel_name")}**.");
} }
} catch { }
catch
{
await e.Channel.SendMessage("Insufficient permissions."); await e.Channel.SendMessage("Insufficient permissions.");
} }
}); });
@ -354,31 +437,40 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "ch").Alias(Prefix + "tch") cgb.CreateCommand(Prefix + "ch").Alias(Prefix + "tch")
.Description("Creates a new text channel with a given name.") .Description("Creates a new text channel with a given name.")
.Parameter("channel_name", ParameterType.Required) .Parameter("channel_name", ParameterType.Required)
.Do(async e => { .Do(async e =>
try { {
if (e.User.ServerPermissions.ManageChannels) { try
{
if (e.User.ServerPermissions.ManageChannels)
{
await e.Server.CreateChannel(e.GetArg("channel_name"), ChannelType.Text); await e.Server.CreateChannel(e.GetArg("channel_name"), ChannelType.Text);
await e.Channel.SendMessage($"Added text channel **{e.GetArg("channel_name")}**."); await e.Channel.SendMessage($"Added text channel **{e.GetArg("channel_name")}**.");
} }
} catch { }
catch
{
await e.Channel.SendMessage("Insufficient permissions."); await e.Channel.SendMessage("Insufficient permissions.");
} }
}); });
cgb.CreateCommand(Prefix + "st").Alias(Prefix + "settopic") cgb.CreateCommand(Prefix + "st").Alias(Prefix + "settopic")
.Alias(Prefix + "topic")
.Description("Sets a topic on the current channel.") .Description("Sets a topic on the current channel.")
.Parameter("topic", ParameterType.Unparsed) .Parameter("topic", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
try { {
if (e.User.ServerPermissions.ManageChannels) var topic = e.GetArg("topic");
await e.Channel.Edit(topic: e.GetArg("topic")); if (string.IsNullOrWhiteSpace(topic))
} catch { } return;
await e.Channel.Edit(topic: topic);
await e.Channel.SendMessage(":ok: **New channel topic set.**");
}); });
cgb.CreateCommand(Prefix + "uid").Alias(Prefix + "userid") cgb.CreateCommand(Prefix + "uid").Alias(Prefix + "userid")
.Description("Shows user ID.") .Description("Shows user ID.")
.Parameter("user", ParameterType.Unparsed) .Parameter("user", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
var usr = e.User; var usr = e.User;
if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault();
if (usr == null) if (usr == null)
@ -396,33 +488,38 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "stats") cgb.CreateCommand(Prefix + "stats")
.Description("Shows some basic stats for Nadeko.") .Description("Shows some basic stats for Nadeko.")
.Do(async e => { .Do(async e =>
{
await e.Channel.SendMessage(await NadekoStats.Instance.GetStats()); await e.Channel.SendMessage(await NadekoStats.Instance.GetStats());
}); });
cgb.CreateCommand(Prefix + "dysyd") cgb.CreateCommand(Prefix + "dysyd")
.Description("Shows some basic stats for Nadeko.") .Description("Shows some basic stats for Nadeko.")
.Do(async e => { .Do(async e =>
{
await e.Channel.SendMessage((await NadekoStats.Instance.GetStats()).Matrix().TrimTo(1990)); await e.Channel.SendMessage((await NadekoStats.Instance.GetStats()).Matrix().TrimTo(1990));
}); });
cgb.CreateCommand(Prefix + "heap") cgb.CreateCommand(Prefix + "heap")
.Description("Shows allocated memory - **Owner Only!**") .Description("Shows allocated memory - **Owner Only!**")
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e => { .Do(async e =>
{
var heap = await Task.Run(() => NadekoStats.Instance.Heap()); var heap = await Task.Run(() => NadekoStats.Instance.Heap());
await e.Channel.SendMessage($"`Heap Size:` {heap}"); await e.Channel.SendMessage($"`Heap Size:` {heap}");
}); });
cgb.CreateCommand(Prefix + "prune") cgb.CreateCommand(Prefix + "prune")
.Parameter("num", ParameterType.Required) .Parameter("num", ParameterType.Required)
.Description("Prunes a number of messages from the current channel.\n**Usage**: .prune 5") .Description("Prunes a number of messages from the current channel.\n**Usage**: .prune 5")
.Do(async e => { .Do(async e =>
{
if (!e.User.ServerPermissions.ManageMessages) return; if (!e.User.ServerPermissions.ManageMessages) return;
int val; int val;
if (string.IsNullOrWhiteSpace(e.GetArg("num")) || !int.TryParse(e.GetArg("num"), out val) || val < 0) if (string.IsNullOrWhiteSpace(e.GetArg("num")) || !int.TryParse(e.GetArg("num"), out val) || val < 0)
return; return;
foreach (var msg in await e.Channel.DownloadMessages(val)) { foreach (var msg in await e.Channel.DownloadMessages(val))
{
await msg.Delete(); await msg.Delete();
await Task.Delay(100); await Task.Delay(100);
} }
@ -431,8 +528,10 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "die") cgb.CreateCommand(Prefix + "die")
.Alias(Prefix + "graceful") .Alias(Prefix + "graceful")
.Description("Shuts the bot down and notifies users about the restart. **Owner Only!**") .Description("Shuts the bot down and notifies users about the restart. **Owner Only!**")
.Do(async e => { .Do(async e =>
if (NadekoBot.IsOwner(e.User.Id)) { {
if (NadekoBot.IsOwner(e.User.Id))
{
await e.Channel.SendMessage("`Shutting down.`"); await e.Channel.SendMessage("`Shutting down.`");
await Task.Delay(2000); await Task.Delay(2000);
Environment.Exit(0); Environment.Exit(0);
@ -442,19 +541,25 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "clr") cgb.CreateCommand(Prefix + "clr")
.Description("Clears some of Nadeko's messages from the current channel. If given a user, will clear the user's messages from the current channel (**Owner Only!**) \n**Usage**: .clr @X") .Description("Clears some of Nadeko's messages from the current channel. If given a user, will clear the user's messages from the current channel (**Owner Only!**) \n**Usage**: .clr @X")
.Parameter("user", ParameterType.Unparsed) .Parameter("user", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
var usrId = NadekoBot.Client.CurrentUser.Id; var usrId = NadekoBot.Client.CurrentUser.Id;
if (!string.IsNullOrWhiteSpace(e.GetArg("user")) && e.User.ServerPermissions.ManageMessages) { if (!string.IsNullOrWhiteSpace(e.GetArg("user")) && e.User.ServerPermissions.ManageMessages)
{
var usr = e.Server.FindUsers(e.GetArg("user")).FirstOrDefault(); var usr = e.Server.FindUsers(e.GetArg("user")).FirstOrDefault();
if (usr != null) if (usr != null)
usrId = usr.Id; usrId = usr.Id;
} }
await Task.Run(async () => { await Task.Run(async () =>
{
var msgs = (await e.Channel.DownloadMessages(100)).Where(m => m.User.Id == usrId); var msgs = (await e.Channel.DownloadMessages(100)).Where(m => m.User.Id == usrId);
foreach (var m in msgs) { foreach (var m in msgs)
try { {
try
{
await m.Delete(); await m.Delete();
} catch { } }
catch { }
await Task.Delay(200); await Task.Delay(200);
} }
@ -465,7 +570,8 @@ namespace NadekoBot.Modules {
.Alias(Prefix + "setname") .Alias(Prefix + "setname")
.Description("Give the bot a new name. **Owner Only!**") .Description("Give the bot a new name. **Owner Only!**")
.Parameter("new_name", ParameterType.Unparsed) .Parameter("new_name", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
if (!NadekoBot.IsOwner(e.User.Id) || e.GetArg("new_name") == null) return; if (!NadekoBot.IsOwner(e.User.Id) || e.GetArg("new_name") == null) return;
await client.CurrentUser.Edit(NadekoBot.Creds.Password, e.GetArg("new_name")); await client.CurrentUser.Edit(NadekoBot.Creds.Password, e.GetArg("new_name"));
@ -475,7 +581,8 @@ namespace NadekoBot.Modules {
.Alias(Prefix + "setavatar") .Alias(Prefix + "setavatar")
.Description("Sets a new avatar image for the NadekoBot. **Owner Only!**") .Description("Sets a new avatar image for the NadekoBot. **Owner Only!**")
.Parameter("img", ParameterType.Unparsed) .Parameter("img", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
if (!NadekoBot.IsOwner(e.User.Id) || string.IsNullOrWhiteSpace(e.GetArg("img"))) if (!NadekoBot.IsOwner(e.User.Id) || string.IsNullOrWhiteSpace(e.GetArg("img")))
return; return;
// Gather user provided URL. // Gather user provided URL.
@ -492,7 +599,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "setgame") cgb.CreateCommand(Prefix + "setgame")
.Description("Sets the bots game. **Owner Only!**") .Description("Sets the bots game. **Owner Only!**")
.Parameter("set_game", ParameterType.Unparsed) .Parameter("set_game", ParameterType.Unparsed)
.Do(e => { .Do(e =>
{
if (!NadekoBot.IsOwner(e.User.Id) || e.GetArg("set_game") == null) return; if (!NadekoBot.IsOwner(e.User.Id) || e.GetArg("set_game") == null) return;
client.SetGame(e.GetArg("set_game")); client.SetGame(e.GetArg("set_game"));
@ -500,9 +608,11 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "checkmyperms") cgb.CreateCommand(Prefix + "checkmyperms")
.Description("Checks your userspecific permissions on this channel.") .Description("Checks your userspecific permissions on this channel.")
.Do(async e => { .Do(async e =>
{
var output = "```\n"; var output = "```\n";
foreach (var p in e.User.ServerPermissions.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any())) { foreach (var p in e.User.ServerPermissions.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any()))
{
output += p.Name + ": " + p.GetValue(e.User.ServerPermissions, null).ToString() + "\n"; output += p.Name + ": " + p.GetValue(e.User.ServerPermissions, null).ToString() + "\n";
} }
output += "```"; output += "```";
@ -516,20 +626,24 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "commsuser") cgb.CreateCommand(Prefix + "commsuser")
.Description("Sets a user for through-bot communication. Only works if server is set. Resets commschannel. **Owner Only!**") .Description("Sets a user for through-bot communication. Only works if server is set. Resets commschannel. **Owner Only!**")
.Parameter("name", ParameterType.Unparsed) .Parameter("name", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
if (!NadekoBot.IsOwner(e.User.Id)) return; if (!NadekoBot.IsOwner(e.User.Id)) return;
commsUser = commsServer?.FindUsers(e.GetArg("name")).FirstOrDefault(); commsUser = commsServer?.FindUsers(e.GetArg("name")).FirstOrDefault();
if (commsUser != null) { if (commsUser != null)
{
commsChannel = null; commsChannel = null;
await e.Channel.SendMessage("User for comms set."); await e.Channel.SendMessage("User for comms set.");
} else }
else
await e.Channel.SendMessage("No server specified or user."); await e.Channel.SendMessage("No server specified or user.");
}); });
cgb.CreateCommand(Prefix + "commsserver") cgb.CreateCommand(Prefix + "commsserver")
.Description("Sets a server for through-bot communication. **Owner Only!**") .Description("Sets a server for through-bot communication. **Owner Only!**")
.Parameter("server", ParameterType.Unparsed) .Parameter("server", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
if (!NadekoBot.IsOwner(e.User.Id)) return; if (!NadekoBot.IsOwner(e.User.Id)) return;
commsServer = client.FindServers(e.GetArg("server")).FirstOrDefault(); commsServer = client.FindServers(e.GetArg("server")).FirstOrDefault();
if (commsServer != null) if (commsServer != null)
@ -541,20 +655,24 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "commschannel") cgb.CreateCommand(Prefix + "commschannel")
.Description("Sets a channel for through-bot communication. Only works if server is set. Resets commsuser. **Owner Only!**") .Description("Sets a channel for through-bot communication. Only works if server is set. Resets commsuser. **Owner Only!**")
.Parameter("ch", ParameterType.Unparsed) .Parameter("ch", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
if (!NadekoBot.IsOwner(e.User.Id)) return; if (!NadekoBot.IsOwner(e.User.Id)) return;
commsChannel = commsServer?.FindChannels(e.GetArg("ch"), ChannelType.Text).FirstOrDefault(); commsChannel = commsServer?.FindChannels(e.GetArg("ch"), ChannelType.Text).FirstOrDefault();
if (commsChannel != null) { if (commsChannel != null)
{
commsUser = null; commsUser = null;
await e.Channel.SendMessage("Server for comms set."); await e.Channel.SendMessage("Server for comms set.");
} else }
else
await e.Channel.SendMessage("No server specified or channel is invalid."); await e.Channel.SendMessage("No server specified or channel is invalid.");
}); });
cgb.CreateCommand(Prefix + "send") cgb.CreateCommand(Prefix + "send")
.Description("Send a message to someone on a different server through the bot. **Owner Only!**\n **Usage**: .send Message text multi word!") .Description("Send a message to someone on a different server through the bot. **Owner Only!**\n **Usage**: .send Message text multi word!")
.Parameter("msg", ParameterType.Unparsed) .Parameter("msg", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
if (!NadekoBot.IsOwner(e.User.Id)) return; if (!NadekoBot.IsOwner(e.User.Id)) return;
if (commsUser != null) if (commsUser != null)
await commsUser.SendMessage(e.GetArg("msg")); await commsUser.SendMessage(e.GetArg("msg"));
@ -568,19 +686,23 @@ namespace NadekoBot.Modules {
.Alias(Prefix + "mentionrole") .Alias(Prefix + "mentionrole")
.Description("Mentions every person from the provided role or roles (separated by a ',') on this server. Requires you to have mention everyone permission.") .Description("Mentions every person from the provided role or roles (separated by a ',') on this server. Requires you to have mention everyone permission.")
.Parameter("roles", ParameterType.Unparsed) .Parameter("roles", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
await Task.Run(async () => { {
await Task.Run(async () =>
{
if (!e.User.ServerPermissions.MentionEveryone) return; if (!e.User.ServerPermissions.MentionEveryone) return;
var arg = e.GetArg("roles").Split(',').Select(r => r.Trim()); var arg = e.GetArg("roles").Split(',').Select(r => r.Trim());
string send = $"--{e.User.Mention} has invoked a mention on the following roles--"; string send = $"--{e.User.Mention} has invoked a mention on the following roles--";
foreach (var roleStr in arg.Where(str => !string.IsNullOrWhiteSpace(str))) { foreach (var roleStr in arg.Where(str => !string.IsNullOrWhiteSpace(str)))
{
var role = e.Server.FindRoles(roleStr).FirstOrDefault(); var role = e.Server.FindRoles(roleStr).FirstOrDefault();
if (role == null) continue; if (role == null) continue;
send += $"\n`{role.Name}`\n"; send += $"\n`{role.Name}`\n";
send += string.Join(", ", role.Members.Select(r => r.Mention)); send += string.Join(", ", role.Members.Select(r => r.Mention));
} }
while (send.Length > 2000) { while (send.Length > 2000)
{
var curstr = send.Substring(0, 2000); var curstr = send.Substring(0, 2000);
await await
e.Channel.Send(curstr.Substring(0, e.Channel.Send(curstr.Substring(0,
@ -594,10 +716,12 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "parsetosql") cgb.CreateCommand(Prefix + "parsetosql")
.Description("Loads exported parsedata from /data/parsedata/ into sqlite database.") .Description("Loads exported parsedata from /data/parsedata/ into sqlite database.")
.Do(async e => { .Do(async e =>
{
if (!NadekoBot.IsOwner(e.User.Id)) if (!NadekoBot.IsOwner(e.User.Id))
return; return;
await Task.Run(() => { await Task.Run(() =>
{
SaveParseToDb<Announcement>("data/parsedata/Announcements.json"); SaveParseToDb<Announcement>("data/parsedata/Announcements.json");
SaveParseToDb<Classes._DataModels.Command>("data/parsedata/CommandsRan.json"); SaveParseToDb<Classes._DataModels.Command>("data/parsedata/CommandsRan.json");
SaveParseToDb<Request>("data/parsedata/Requests.json"); SaveParseToDb<Request>("data/parsedata/Requests.json");
@ -609,14 +733,17 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "unstuck") cgb.CreateCommand(Prefix + "unstuck")
.Description("Clears the message queue. **Owner Only!**") .Description("Clears the message queue. **Owner Only!**")
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.Do(e => { .Do(e =>
{
NadekoBot.Client.MessageQueue.Clear(); NadekoBot.Client.MessageQueue.Clear();
}); });
cgb.CreateCommand(Prefix + "donators") cgb.CreateCommand(Prefix + "donators")
.Description("List of lovely people who donated to keep this project alive.") .Description("List of lovely people who donated to keep this project alive.")
.Do(async e => { .Do(async e =>
await Task.Run(async () => { {
await Task.Run(async () =>
{
var rows = DbHandler.Instance.GetAllRows<Donator>(); var rows = DbHandler.Instance.GetAllRows<Donator>();
var donatorsOrdered = rows.OrderByDescending(d => d.Amount); var donatorsOrdered = rows.OrderByDescending(d => d.Amount);
string str = $"**Thanks to the people listed below for making this project happen!**\n"; string str = $"**Thanks to the people listed below for making this project happen!**\n";
@ -632,64 +759,65 @@ namespace NadekoBot.Modules {
.Parameter("donator") .Parameter("donator")
.Parameter("amount") .Parameter("amount")
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e => { .Do(async e =>
await Task.Run(() => { {
await Task.Run(() =>
{
if (!NadekoBot.IsOwner(e.User.Id)) if (!NadekoBot.IsOwner(e.User.Id))
return; return;
var donator = e.Server.FindUsers(e.GetArg("donator")).FirstOrDefault(); var donator = e.Server.FindUsers(e.GetArg("donator")).FirstOrDefault();
var amount = int.Parse(e.GetArg("amount")); var amount = int.Parse(e.GetArg("amount"));
if (donator == null) return; if (donator == null) return;
try { try
DbHandler.Instance.InsertData(new Donator { {
DbHandler.Instance.InsertData(new Donator
{
Amount = amount, Amount = amount,
UserName = donator.Name, UserName = donator.Name,
UserId = (long)e.User.Id UserId = (long)e.User.Id
}); });
e.Channel.SendMessage("Successfuly added a new donator. 👑"); e.Channel.SendMessage("Successfuly added a new donator. 👑");
} catch { } }
catch { }
}); });
}); });
cgb.CreateCommand(Prefix + "topic")
.Description("Sets current channel's topic.")
.Parameter("topic", ParameterType.Unparsed)
.AddCheck(SimpleCheckers.ManageChannels())
.Do(async e => {
var topic = e.GetArg("topic");
if (string.IsNullOrWhiteSpace(topic))
return;
await e.Channel.Edit(topic: topic);
await e.Channel.SendMessage(":ok: **New channel topic set.**");
});
cgb.CreateCommand(Prefix + "videocall") cgb.CreateCommand(Prefix + "videocall")
.Description("Creates a private appear.in video call link for you and other mentioned people. The link is sent to mentioned people via a private message.") .Description("Creates a private appear.in video call link for you and other mentioned people. The link is sent to mentioned people via a private message.")
.Parameter("arg", ParameterType.Unparsed) .Parameter("arg", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
try { {
try
{
var allUsrs = e.Message.MentionedUsers.Union(new User[] { e.User }); var allUsrs = e.Message.MentionedUsers.Union(new User[] { e.User });
var allUsrsArray = allUsrs as User[] ?? allUsrs.ToArray(); var allUsrsArray = allUsrs as User[] ?? allUsrs.ToArray();
var str = allUsrsArray.Aggregate("http://appear.in/", (current, usr) => current + Uri.EscapeUriString(usr.Name[0].ToString())); var str = allUsrsArray.Aggregate("http://appear.in/", (current, usr) => current + Uri.EscapeUriString(usr.Name[0].ToString()));
str += new Random().Next(); str += new Random().Next();
foreach (var usr in allUsrsArray) { foreach (var usr in allUsrsArray)
{
await usr.SendMessage(str); await usr.SendMessage(str);
} }
} catch (Exception ex) { }
catch (Exception ex)
{
Console.WriteLine(ex); Console.WriteLine(ex);
} }
}); });
}); });
} }
public void SaveParseToDb<T>(string where) where T : IDataModel { public void SaveParseToDb<T>(string where) where T : IDataModel
try { {
try
{
var data = File.ReadAllText(where); var data = File.ReadAllText(where);
var arr = JObject.Parse(data)["results"] as JArray; var arr = JObject.Parse(data)["results"] as JArray;
if (arr == null) if (arr == null)
return; return;
var objects = arr.Select(x => x.ToObject<T>()); var objects = arr.Select(x => x.ToObject<T>());
DbHandler.Instance.InsertMany(objects); DbHandler.Instance.InsertMany(objects);
} catch { } }
catch { }
} }
} }
} }

View File

@ -34,15 +34,14 @@ namespace NadekoBot.Modules.Gambling
.Parameter("role", ParameterType.Optional) .Parameter("role", ParameterType.Optional)
.Do(RaffleFunc()); .Do(RaffleFunc());
cgb.CreateCommand(Prefix + "$$") cgb.CreateCommand(Prefix + "$$")
.Description("Check how many NadekoFlowers you have.") .Description(string.Format("Check how much {0}s you have.", NadekoBot.Config.CurrencyName))
.Do(NadekoFlowerCheckFunc()); .Do(NadekoFlowerCheckFunc());
cgb.CreateCommand(Prefix + "give") cgb.CreateCommand(Prefix + "give")
.Description("Give someone a certain amount of flowers") .Description(string.Format("Give someone a certain amount of {0}s", NadekoBot.Config.CurrencyName))
.Parameter("amount", ParameterType.Required) .Parameter("amount", ParameterType.Required)
.Parameter("receiver", ParameterType.Unparsed) .Parameter("receiver", ParameterType.Unparsed)
.Do(async e => .Do(async e =>
{ {
var amountStr = e.GetArg("amount")?.Trim(); var amountStr = e.GetArg("amount")?.Trim();
long amount; long amount;
if (!long.TryParse(amountStr, out amount) || amount < 0) if (!long.TryParse(amountStr, out amount) || amount < 0)
@ -58,14 +57,14 @@ namespace NadekoBot.Modules.Gambling
if (userFlowers < amount) if (userFlowers < amount)
{ {
await e.Channel.SendMessage($"{e.User.Mention} You don't have enough flowers. You have only {userFlowers}🌸."); await e.Channel.SendMessage($"{e.User.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You have only {userFlowers}{NadekoBot.Config.CurrencySign}.");
return; return;
} }
await FlowersHandler.RemoveFlowersAsync(e.User, "Gift", (int)amount); await FlowersHandler.RemoveFlowersAsync(e.User, "Gift", (int)amount);
await FlowersHandler.AddFlowersAsync(mentionedUser, "Gift", (int)amount); await FlowersHandler.AddFlowersAsync(mentionedUser, "Gift", (int)amount);
await e.Channel.SendMessage($"{e.User.Mention} successfully sent {amount}🌸 to {mentionedUser.Mention}!"); await e.Channel.SendMessage($"{e.User.Mention} successfully sent {amount} {NadekoBot.Config.CurrencyName}s to {mentionedUser.Mention}!");
}); });
}); });
@ -76,10 +75,10 @@ namespace NadekoBot.Modules.Gambling
return async e => return async e =>
{ {
var pts = GetUserFlowers(e.User.Id); var pts = GetUserFlowers(e.User.Id);
var str = $"`You have {pts} NadekoFlowers".SnPl((int)pts) + "`\n"; var str = $"`You have {pts} {NadekoBot.Config.CurrencyName}s".SnPl((int)pts) + "`\n";
for (var i = 0; i < pts; i++) for (var i = 0; i < pts; i++)
{ {
str += "🌸"; str += NadekoBot.Config.CurrencySign;
} }
await e.Channel.SendMessage(str); await e.Channel.SendMessage(str);
}; };

View File

@ -1,17 +1,18 @@
using System; using Discord.Commands;
using System.Linq;
using Discord.Modules; using Discord.Modules;
using NadekoBot.Commands; using NadekoBot.Commands;
using Newtonsoft.Json.Linq;
using System.IO;
using Discord.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System;
using System.Linq;
namespace NadekoBot.Modules { namespace NadekoBot.Modules
internal class Games : DiscordModule { {
internal class Games : DiscordModule
{
private readonly Random rng = new Random(); private readonly Random rng = new Random();
public Games() { public Games()
{
commands.Add(new Trivia(this)); commands.Add(new Trivia(this));
commands.Add(new SpeedTyping(this)); commands.Add(new SpeedTyping(this));
commands.Add(new PollCommand(this)); commands.Add(new PollCommand(this));
@ -20,8 +21,10 @@ namespace NadekoBot.Modules {
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Games; public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Games;
public override void Install(ModuleManager manager) { public override void Install(ModuleManager manager)
manager.CreateCommands("", cgb => { {
manager.CreateCommands("", cgb =>
{
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
@ -30,7 +33,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "choose") cgb.CreateCommand(Prefix + "choose")
.Description("Chooses a thing from a list of things\n**Usage**: >choose Get up;Sleep;Sleep more") .Description("Chooses a thing from a list of things\n**Usage**: >choose Get up;Sleep;Sleep more")
.Parameter("list", Discord.Commands.ParameterType.Unparsed) .Parameter("list", Discord.Commands.ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
var arg = e.GetArg("list"); var arg = e.GetArg("list");
if (string.IsNullOrWhiteSpace(arg)) if (string.IsNullOrWhiteSpace(arg))
return; return;
@ -43,23 +47,28 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "8ball") cgb.CreateCommand(Prefix + "8ball")
.Description("Ask the 8ball a yes/no question.") .Description("Ask the 8ball a yes/no question.")
.Parameter("question", Discord.Commands.ParameterType.Unparsed) .Parameter("question", Discord.Commands.ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
var question = e.GetArg("question"); var question = e.GetArg("question");
if (string.IsNullOrWhiteSpace(question)) if (string.IsNullOrWhiteSpace(question))
return; return;
try { try
{
await e.Channel.SendMessage( await e.Channel.SendMessage(
$":question: **Question**: `{question}` \n🎱 **8Ball Answers**: `{NadekoBot.Config._8BallResponses[rng.Next(0, NadekoBot.Config._8BallResponses.Length)]}`"); $":question: **Question**: `{question}` \n🎱 **8Ball Answers**: `{NadekoBot.Config._8BallResponses[rng.Next(0, NadekoBot.Config._8BallResponses.Length)]}`");
} catch { } }
catch { }
}); });
cgb.CreateCommand(Prefix + "attack") cgb.CreateCommand(Prefix + "attack")
.Description("Attack a person. Supported attacks: 'splash', 'strike', 'burn', 'surge'.\n**Usage**: >attack strike @User") .Description("Attack a person. Supported attacks: 'splash', 'strike', 'burn', 'surge'.\n**Usage**: >attack strike @User")
.Parameter("attack_type", Discord.Commands.ParameterType.Required) .Parameter("attack_type", Discord.Commands.ParameterType.Required)
.Parameter("target", Discord.Commands.ParameterType.Required) .Parameter("target", Discord.Commands.ParameterType.Required)
.Do(async e => { .Do(async e =>
{
var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault(); var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault();
if (usr == null) { if (usr == null)
{
await e.Channel.SendMessage("No such person."); await e.Channel.SendMessage("No such person.");
return; return;
} }
@ -67,9 +76,12 @@ namespace NadekoBot.Modules {
var response = ""; var response = "";
var dmg = GetDamage(usrType, e.GetArg("attack_type").ToLowerInvariant()); var dmg = GetDamage(usrType, e.GetArg("attack_type").ToLowerInvariant());
response = e.GetArg("attack_type") + (e.GetArg("attack_type") == "splash" ? "es " : "s ") + $"{usr.Mention}{GetImage(usrType)} for {dmg}\n"; response = e.GetArg("attack_type") + (e.GetArg("attack_type") == "splash" ? "es " : "s ") + $"{usr.Mention}{GetImage(usrType)} for {dmg}\n";
if (dmg >= 65) { if (dmg >= 65)
{
response += "It's super effective!"; response += "It's super effective!";
} else if (dmg <= 35) { }
else if (dmg <= 35)
{
response += "Ineffective!"; response += "Ineffective!";
} }
await e.Channel.SendMessage($"{ e.User.Mention }{GetImage(GetType(e.User.Id))} {response}"); await e.Channel.SendMessage($"{ e.User.Mention }{GetImage(GetType(e.User.Id))} {response}");
@ -78,9 +90,11 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "poketype") cgb.CreateCommand(Prefix + "poketype")
.Parameter("target", Discord.Commands.ParameterType.Required) .Parameter("target", Discord.Commands.ParameterType.Required)
.Description("Gets the users element type. Use this to do more damage with strike!") .Description("Gets the users element type. Use this to do more damage with strike!")
.Do(async e => { .Do(async e =>
{
var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault(); var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault();
if (usr == null) { if (usr == null)
{
await e.Channel.SendMessage("No such person."); await e.Channel.SendMessage("No such person.");
return; return;
} }
@ -90,10 +104,12 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "rps") cgb.CreateCommand(Prefix + "rps")
.Description("Play a game of rocket paperclip scissors with nadkeo.\n**Usage**: >rps scissors") .Description("Play a game of rocket paperclip scissors with nadkeo.\n**Usage**: >rps scissors")
.Parameter("input", ParameterType.Required) .Parameter("input", ParameterType.Required)
.Do(async e => { .Do(async e =>
{
var input = e.GetArg("input").Trim(); var input = e.GetArg("input").Trim();
int pick; int pick;
switch (input) { switch (input)
{
case "r": case "r":
case "rock": case "rock":
case "rocket": case "rocket":
@ -129,7 +145,8 @@ namespace NadekoBot.Modules {
.Description("Prints a customizable Linux interjection") .Description("Prints a customizable Linux interjection")
.Parameter("gnu", ParameterType.Required) .Parameter("gnu", ParameterType.Required)
.Parameter("linux", ParameterType.Required) .Parameter("linux", ParameterType.Required)
.Do(async e => { .Do(async e =>
{
var guhnoo = e.Args[0]; var guhnoo = e.Args[0];
var loonix = e.Args[1]; var loonix = e.Args[1];
@ -157,8 +174,10 @@ There really is a {loonix}, and these people are using it, but it is just a part
🌟 or 💫 or Fairy 🌟 or 💫 or Fairy
*/ */
private string GetImage(PokeType t) { private string GetImage(PokeType t)
switch (t) { {
switch (t)
{
case PokeType.WATER: case PokeType.WATER:
return "💦"; return "💦";
case PokeType.GRASS: case PokeType.GRASS:
@ -172,9 +191,11 @@ There really is a {loonix}, and these people are using it, but it is just a part
} }
} }
private int GetDamage(PokeType targetType, string v) { private int GetDamage(PokeType targetType, string v)
{
var rng = new Random(); var rng = new Random();
switch (v) { switch (v)
{
case "splash": //water case "splash": //water
if (targetType == PokeType.FIRE) if (targetType == PokeType.FIRE)
return rng.Next(65, 100); return rng.Next(65, 100);
@ -210,27 +231,34 @@ There really is a {loonix}, and these people are using it, but it is just a part
} }
} }
private PokeType GetType(ulong id) { private PokeType GetType(ulong id)
{
if (id == 113760353979990024) if (id == 113760353979990024)
return PokeType.FIRE; return PokeType.FIRE;
var remainder = id % 10; var remainder = id % 10;
if (remainder < 3) if (remainder < 3)
return PokeType.WATER; return PokeType.WATER;
else if (remainder >= 3 && remainder < 5) { else if (remainder >= 3 && remainder < 5)
{
return PokeType.GRASS; return PokeType.GRASS;
} else if (remainder >= 5 && remainder < 8) { }
else if (remainder >= 5 && remainder < 8)
{
return PokeType.FIRE; return PokeType.FIRE;
} else { }
else {
return PokeType.ELECTRICAL; return PokeType.ELECTRICAL;
} }
} }
private enum PokeType { private enum PokeType
{
WATER, GRASS, FIRE, ELECTRICAL WATER, GRASS, FIRE, ELECTRICAL
} }
private string GetRPSPick(int i) { private string GetRPSPick(int i)
{
if (i == 0) if (i == 0)
return "rocket"; return "rocket";
else if (i == 1) else if (i == 1)

View File

@ -3,16 +3,18 @@ using Discord.Commands;
using Discord.Modules; using Discord.Modules;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Classes.Music; using NadekoBot.Classes.Music;
using NadekoBot.Classes.Permissions;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using NadekoBot.Classes.Permissions;
using Timer = System.Timers.Timer; using Timer = System.Timers.Timer;
namespace NadekoBot.Modules { namespace NadekoBot.Modules
internal class Music : DiscordModule { {
internal class Music : DiscordModule
{
public static ConcurrentDictionary<Server, MusicPlayer> MusicPlayers = new ConcurrentDictionary<Server, MusicPlayer>(); public static ConcurrentDictionary<Server, MusicPlayer> MusicPlayers = new ConcurrentDictionary<Server, MusicPlayer>();
public static ConcurrentDictionary<ulong, float> DefaultMusicVolumes = new ConcurrentDictionary<ulong, float>(); public static ConcurrentDictionary<ulong, float> DefaultMusicVolumes = new ConcurrentDictionary<ulong, float>();
@ -21,24 +23,46 @@ namespace NadekoBot.Modules {
private bool setgameEnabled = false; private bool setgameEnabled = false;
public Music() { public Music()
{
setgameTimer.Interval = 20000; setgameTimer.Interval = 20000;
setgameTimer.Elapsed += (s, e) => { setgameTimer.Elapsed += (s, e) =>
try { {
try
{
var num = MusicPlayers.Count(kvp => kvp.Value.CurrentSong != null); var num = MusicPlayers.Count(kvp => kvp.Value.CurrentSong != null);
NadekoBot.Client.SetGame($"{num} songs".SnPl(num) + $", {MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count())} queued"); NadekoBot.Client.SetGame($"{num} songs".SnPl(num) + $", {MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count())} queued");
} catch { } }
catch { }
}; };
// ready for 1.0
//NadekoBot.Client.UserUpdated += (s, e) =>
//{
// try
// {
// if (e.Before.VoiceChannel != e.After.VoiceChannel &&
// e.Before.VoiceChannel.Members.Count() == 0)
// {
// MusicPlayer musicPlayer;
// if (!MusicPlayers.TryRemove(e.Server, out musicPlayer)) return;
// musicPlayer.Destroy();
// }
// }
// catch { }
//};
} }
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Music; public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Music;
public override void Install(ModuleManager manager) { public override void Install(ModuleManager manager)
{
var client = NadekoBot.Client; var client = NadekoBot.Client;
manager.CreateCommands(Prefix, cgb => { manager.CreateCommands(Prefix, cgb =>
{
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
@ -47,7 +71,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("n") cgb.CreateCommand("n")
.Alias("next") .Alias("next")
.Description("Goes to the next song in the queue.") .Description("Goes to the next song in the queue.")
.Do(e => { .Do(e =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return;
musicPlayer.Next(); musicPlayer.Next();
@ -56,8 +81,10 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("s") cgb.CreateCommand("s")
.Alias("stop") .Alias("stop")
.Description("Stops the music and clears the playlist. Stays in the channel.") .Description("Stops the music and clears the playlist. Stays in the channel.")
.Do(async e => { .Do(async e =>
await Task.Run(() => { {
await Task.Run(() =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return;
musicPlayer.Stop(); musicPlayer.Stop();
@ -67,8 +94,10 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("d") cgb.CreateCommand("d")
.Alias("destroy") .Alias("destroy")
.Description("Completely stops the music and unbinds the bot from the channel. (may cause weird behaviour)") .Description("Completely stops the music and unbinds the bot from the channel. (may cause weird behaviour)")
.Do(async e => { .Do(async e =>
await Task.Run(() => { {
await Task.Run(() =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryRemove(e.Server, out musicPlayer)) return; if (!MusicPlayers.TryRemove(e.Server, out musicPlayer)) return;
musicPlayer.Destroy(); musicPlayer.Destroy();
@ -78,7 +107,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("p") cgb.CreateCommand("p")
.Alias("pause") .Alias("pause")
.Description("Pauses or Unpauses the song.") .Description("Pauses or Unpauses the song.")
.Do(async e => { .Do(async e =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return;
musicPlayer.TogglePause(); musicPlayer.TogglePause();
@ -92,16 +122,19 @@ namespace NadekoBot.Modules {
.Alias("yq") .Alias("yq")
.Description("Queue a song using keywords or a link. Bot will join your voice channel. **You must be in a voice channel**.\n**Usage**: `!m q Dream Of Venice`") .Description("Queue a song using keywords or a link. Bot will join your voice channel. **You must be in a voice channel**.\n**Usage**: `!m q Dream Of Venice`")
.Parameter("query", ParameterType.Unparsed) .Parameter("query", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
await QueueSong(e.Channel, e.User.VoiceChannel, e.GetArg("query")); await QueueSong(e.Channel, e.User.VoiceChannel, e.GetArg("query"));
}); });
cgb.CreateCommand("lq") cgb.CreateCommand("lq")
.Alias("ls").Alias("lp") .Alias("ls").Alias("lp")
.Description("Lists up to 15 currently queued songs.") .Description("Lists up to 15 currently queued songs.")
.Do(async e => { .Do(async e =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
{
await e.Channel.SendMessage("🎵 No active music player."); await e.Channel.SendMessage("🎵 No active music player.");
return; return;
} }
@ -117,7 +150,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("np") cgb.CreateCommand("np")
.Alias("playing") .Alias("playing")
.Description("Shows the song currently playing.") .Description("Shows the song currently playing.")
.Do(async e => { .Do(async e =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
return; return;
@ -130,13 +164,15 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("vol") cgb.CreateCommand("vol")
.Description("Sets the music volume 0-150%") .Description("Sets the music volume 0-150%")
.Parameter("val", ParameterType.Required) .Parameter("val", ParameterType.Required)
.Do(async e => { .Do(async e =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
return; return;
var arg = e.GetArg("val"); var arg = e.GetArg("val");
int volume; int volume;
if (!int.TryParse(arg, out volume)) { if (!int.TryParse(arg, out volume))
{
await e.Channel.SendMessage("Volume number invalid."); await e.Channel.SendMessage("Volume number invalid.");
return; return;
} }
@ -148,10 +184,12 @@ namespace NadekoBot.Modules {
.Alias("defvol") .Alias("defvol")
.Description("Sets the default music volume when music playback is started (0-100). Does not persist through restarts.\n**Usage**: !m dv 80") .Description("Sets the default music volume when music playback is started (0-100). Does not persist through restarts.\n**Usage**: !m dv 80")
.Parameter("val", ParameterType.Required) .Parameter("val", ParameterType.Required)
.Do(async e => { .Do(async e =>
{
var arg = e.GetArg("val"); var arg = e.GetArg("val");
float volume; float volume;
if (!float.TryParse(arg, out volume) || volume < 0 || volume > 100) { if (!float.TryParse(arg, out volume) || volume < 0 || volume > 100)
{
await e.Channel.SendMessage("Volume number invalid."); await e.Channel.SendMessage("Volume number invalid.");
return; return;
} }
@ -161,7 +199,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("min").Alias("mute") cgb.CreateCommand("min").Alias("mute")
.Description("Sets the music volume to 0%") .Description("Sets the music volume to 0%")
.Do(e => { .Do(e =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
return; return;
@ -170,7 +209,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("max") cgb.CreateCommand("max")
.Description("Sets the music volume to 100% (real max is actually 150%).") .Description("Sets the music volume to 100% (real max is actually 150%).")
.Do(e => { .Do(e =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
return; return;
@ -179,7 +219,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("half") cgb.CreateCommand("half")
.Description("Sets the music volume to 50%.") .Description("Sets the music volume to 50%.")
.Do(e => { .Do(e =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
return; return;
@ -188,11 +229,13 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("sh") cgb.CreateCommand("sh")
.Description("Shuffles the current playlist.") .Description("Shuffles the current playlist.")
.Do(async e => { .Do(async e =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
return; return;
if (musicPlayer.Playlist.Count < 2) { if (musicPlayer.Playlist.Count < 2)
{
await e.Channel.SendMessage("💢 Not enough songs in order to perform the shuffle."); await e.Channel.SendMessage("💢 Not enough songs in order to perform the shuffle.");
return; return;
} }
@ -204,7 +247,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("setgame") cgb.CreateCommand("setgame")
.Description("Sets the game of the bot to the number of songs playing. **Owner only**") .Description("Sets the game of the bot to the number of songs playing. **Owner only**")
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e => { .Do(async e =>
{
await e.Channel.SendMessage("❗This command is deprecated. " + await e.Channel.SendMessage("❗This command is deprecated. " +
"Use:\n `.ropl`\n `.adpl %playing% songs, %queued% queued.` instead.\n " + "Use:\n `.ropl`\n `.adpl %playing% songs, %queued% queued.` instead.\n " +
"It even persists through restarts."); "It even persists through restarts.");
@ -213,8 +257,10 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("pl") cgb.CreateCommand("pl")
.Description("Queues up to 25 songs from a youtube playlist specified by a link, or keywords.") .Description("Queues up to 25 songs from a youtube playlist specified by a link, or keywords.")
.Parameter("playlist", ParameterType.Unparsed) .Parameter("playlist", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
if (e.User.VoiceChannel?.Server != e.Server) { {
if (e.User.VoiceChannel?.Server != e.Server)
{
await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it."); await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.");
return; return;
} }
@ -224,10 +270,13 @@ namespace NadekoBot.Modules {
var count = idArray.Count(); var count = idArray.Count();
var msg = var msg =
await e.Channel.SendMessage($"🎵 `Attempting to queue {count} songs".SnPl(count) + "...`"); await e.Channel.SendMessage($"🎵 `Attempting to queue {count} songs".SnPl(count) + "...`");
foreach (var id in idArray) { foreach (var id in idArray)
try { {
try
{
await QueueSong(e.Channel, e.User.VoiceChannel, id, true); await QueueSong(e.Channel, e.User.VoiceChannel, id, true);
} catch { } }
catch { }
} }
await msg.Edit("🎵 `Playlist queue complete.`"); await msg.Edit("🎵 `Playlist queue complete.`");
}); });
@ -236,24 +285,30 @@ namespace NadekoBot.Modules {
.Description("Queues up to 50 songs from a directory. **Owner Only!**") .Description("Queues up to 50 songs from a directory. **Owner Only!**")
.Parameter("directory", ParameterType.Unparsed) .Parameter("directory", ParameterType.Unparsed)
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly()) .AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
.Do(async e => { .Do(async e =>
{
var arg = e.GetArg("directory"); var arg = e.GetArg("directory");
if (string.IsNullOrWhiteSpace(e.GetArg("directory"))) if (string.IsNullOrWhiteSpace(e.GetArg("directory")))
return; return;
try { try
{
var fileEnum = System.IO.Directory.EnumerateFiles(e.GetArg("directory")).Take(50); var fileEnum = System.IO.Directory.EnumerateFiles(e.GetArg("directory")).Take(50);
foreach (var file in fileEnum) { foreach (var file in fileEnum)
{
await QueueSong(e.Channel, e.User.VoiceChannel, file, true, MusicType.Local); await QueueSong(e.Channel, e.User.VoiceChannel, file, true, MusicType.Local);
} }
await e.Channel.SendMessage("🎵 `Directory queue complete.`"); await e.Channel.SendMessage("🎵 `Directory queue complete.`");
} catch { } }
catch { }
}); });
cgb.CreateCommand("radio").Alias("ra") cgb.CreateCommand("radio").Alias("ra")
.Description("Queues a direct radio stream from a link.") .Description("Queues a direct radio stream from a link.")
.Parameter("radio_link", ParameterType.Required) .Parameter("radio_link", ParameterType.Required)
.Do(async e => { .Do(async e =>
if (e.User.VoiceChannel?.Server != e.Server) { {
if (e.User.VoiceChannel?.Server != e.Server)
{
await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it."); await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.");
return; return;
} }
@ -264,7 +319,8 @@ namespace NadekoBot.Modules {
.Description("Queues a local file by specifying a full path. **Owner Only!**") .Description("Queues a local file by specifying a full path. **Owner Only!**")
.Parameter("path", ParameterType.Unparsed) .Parameter("path", ParameterType.Unparsed)
.AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly()) .AddCheck(Classes.Permissions.SimpleCheckers.OwnerOnly())
.Do(async e => { .Do(async e =>
{
var arg = e.GetArg("path"); var arg = e.GetArg("path");
if (string.IsNullOrWhiteSpace(arg)) if (string.IsNullOrWhiteSpace(arg))
return; return;
@ -273,7 +329,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("mv") cgb.CreateCommand("mv")
.Description("Moves the bot to your voice channel. (works only if music is already playing)") .Description("Moves the bot to your voice channel. (works only if music is already playing)")
.Do(e => { .Do(e =>
{
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
var voiceChannel = e.User.VoiceChannel; var voiceChannel = e.User.VoiceChannel;
if (voiceChannel == null || voiceChannel.Server != e.Server || !MusicPlayers.TryGetValue(e.Server, out musicPlayer)) if (voiceChannel == null || voiceChannel.Server != e.Server || !MusicPlayers.TryGetValue(e.Server, out musicPlayer))
@ -284,19 +341,23 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("rm") cgb.CreateCommand("rm")
.Description("Remove a song by its # in the queue, or 'all' to remove whole queue.") .Description("Remove a song by its # in the queue, or 'all' to remove whole queue.")
.Parameter("num", ParameterType.Required) .Parameter("num", ParameterType.Required)
.Do(async e => { .Do(async e =>
{
var arg = e.GetArg("num"); var arg = e.GetArg("num");
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) { if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
{
return; return;
} }
if (arg?.ToLower() == "all") { if (arg?.ToLower() == "all")
{
musicPlayer.ClearQueue(); musicPlayer.ClearQueue();
await e.Channel.SendMessage($"🎵`Queue cleared!`"); await e.Channel.SendMessage($"🎵`Queue cleared!`");
return; return;
} }
int num; int num;
if (!int.TryParse(arg, out num)) { if (!int.TryParse(arg, out num))
{
return; return;
} }
if (num <= 0 || num > musicPlayer.Playlist.Count) if (num <= 0 || num > musicPlayer.Playlist.Count)
@ -309,11 +370,14 @@ namespace NadekoBot.Modules {
cgb.CreateCommand("cleanup") cgb.CreateCommand("cleanup")
.Description("Cleans up hanging voice connections. **Owner Only!**") .Description("Cleans up hanging voice connections. **Owner Only!**")
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.Do(e => { .Do(e =>
foreach (var kvp in MusicPlayers) { {
foreach (var kvp in MusicPlayers)
{
var songs = kvp.Value.Playlist; var songs = kvp.Value.Playlist;
var currentSong = kvp.Value.CurrentSong; var currentSong = kvp.Value.CurrentSong;
if (songs.Count == 0 && currentSong == null) { if (songs.Count == 0 && currentSong == null)
{
MusicPlayer throwaway; MusicPlayer throwaway;
MusicPlayers.TryRemove(kvp.Key, out throwaway); MusicPlayers.TryRemove(kvp.Key, out throwaway);
throwaway.Destroy(); throwaway.Destroy();
@ -331,8 +395,10 @@ namespace NadekoBot.Modules {
}); });
} }
private async Task QueueSong(Channel textCh, Channel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal) { private async Task QueueSong(Channel textCh, Channel voiceCh, string query, bool silent = false, MusicType musicType = MusicType.Normal)
if (voiceCh == null || voiceCh.Server != textCh.Server) { {
if (voiceCh == null || voiceCh.Server != textCh.Server)
{
if (!silent) if (!silent)
await textCh.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining."); await textCh.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.");
throw new ArgumentNullException(nameof(voiceCh)); throw new ArgumentNullException(nameof(voiceCh));
@ -340,25 +406,32 @@ namespace NadekoBot.Modules {
if (string.IsNullOrWhiteSpace(query) || query.Length < 3) if (string.IsNullOrWhiteSpace(query) || query.Length < 3)
throw new ArgumentException("💢 Invalid query for queue song.", nameof(query)); throw new ArgumentException("💢 Invalid query for queue song.", nameof(query));
var musicPlayer = MusicPlayers.GetOrAdd(textCh.Server, server => { var musicPlayer = MusicPlayers.GetOrAdd(textCh.Server, server =>
{
float? vol = null; float? vol = null;
float throwAway; float throwAway;
if (DefaultMusicVolumes.TryGetValue(server.Id, out throwAway)) if (DefaultMusicVolumes.TryGetValue(server.Id, out throwAway))
vol = throwAway; vol = throwAway;
var mp = new MusicPlayer(voiceCh, vol); var mp = new MusicPlayer(voiceCh, vol);
mp.OnCompleted += async (s, song) => { mp.OnCompleted += async (s, song) =>
try { {
try
{
await textCh.SendMessage($"🎵`Finished`{song.PrettyName}"); await textCh.SendMessage($"🎵`Finished`{song.PrettyName}");
} catch { } }
catch { }
}; };
mp.OnStarted += async (s, song) => { mp.OnStarted += async (s, song) =>
{
var sender = s as MusicPlayer; var sender = s as MusicPlayer;
if (sender == null) if (sender == null)
return; return;
try { try
{
var msgTxt = $"🎵`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`"; var msgTxt = $"🎵`Playing`{song.PrettyName} `Vol: {(int)(sender.Volume * 100)}%`";
await textCh.SendMessage(msgTxt); await textCh.SendMessage(msgTxt);
} catch { } }
catch { }
}; };
return mp; return mp;
}); });

View File

@ -69,5 +69,7 @@
"https://media.giphy.com/media/12hvLuZ7uzvCvK/giphy.gif", "https://media.giphy.com/media/12hvLuZ7uzvCvK/giphy.gif",
"http://gallery1.anivide.com/_full/65030_1382582341.gif", "http://gallery1.anivide.com/_full/65030_1382582341.gif",
"https://49.media.tumblr.com/8e8a099c4eba22abd3ec0f70fd087cce/tumblr_nxovj9oY861ur1mffo1_500.gif " "https://49.media.tumblr.com/8e8a099c4eba22abd3ec0f70fd087cce/tumblr_nxovj9oY861ur1mffo1_500.gif "
] ],
"CurrencySign": "🌸",
"CurrencyName": "NadekoFlower"
} }