music and clash of clans readded

This commit is contained in:
Master Kwoth
2017-05-24 06:43:00 +02:00
parent 2df415341c
commit c183e8ad58
22 changed files with 793 additions and 728 deletions

View File

@@ -1,81 +1,23 @@
using Discord.Commands;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Discord;
using NadekoBot.Services;
using NadekoBot.Attributes;
using NadekoBot.Services.Database.Models;
using System.Linq;
using NadekoBot.Extensions;
using System.Threading;
using NadekoBot.Services.ClashOfClans;
namespace NadekoBot.Modules.ClashOfClans
{
[NadekoModule("ClashOfClans", ",")]
public class ClashOfClans : NadekoTopLevelModule
{
public static ConcurrentDictionary<ulong, List<ClashWar>> ClashWars { get; set; }
private readonly ClashOfClansService _service;
private static Timer checkWarTimer { get; }
static ClashOfClans()
public ClashOfClans(ClashOfClansService service)
{
using (var uow = DbHandler.UnitOfWork())
{
ClashWars = new ConcurrentDictionary<ulong, List<ClashWar>>(
uow.ClashOfClans
.GetAllWars()
.Select(cw =>
{
cw.Channel = NadekoBot.Client.GetGuild(cw.GuildId)?
.GetTextChannel(cw.ChannelId);
return cw;
})
.Where(cw => cw.Channel != null)
.GroupBy(cw => cw.GuildId)
.ToDictionary(g => g.Key, g => g.ToList()));
}
checkWarTimer = new Timer(async _ =>
{
foreach (var kvp in ClashWars)
{
foreach (var war in kvp.Value)
{
try { await CheckWar(TimeSpan.FromHours(2), war).ConfigureAwait(false); } catch { }
}
}
}, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
}
private static async Task CheckWar(TimeSpan callExpire, ClashWar war)
{
var Bases = war.Bases;
for (var i = 0; i < Bases.Count; i++)
{
var callUser = Bases[i].CallUser;
if (callUser == null) continue;
if ((!Bases[i].BaseDestroyed) && DateTime.UtcNow - Bases[i].TimeAdded >= callExpire)
{
if (Bases[i].Stars != 3)
Bases[i].BaseDestroyed = true;
else
Bases[i] = null;
try
{
SaveWar(war);
await war.Channel.SendErrorAsync(GetTextStatic("claim_expired",
NadekoBot.Localization.GetCultureInfo(war.Channel.GuildId),
typeof(ClashOfClans).Name.ToLowerInvariant(),
Format.Bold(Bases[i].CallUser),
war.ShortPrint()));
}
catch { }
}
}
_service = service;
}
[NadekoCommand, Usage, Description, Aliases]
@@ -92,18 +34,18 @@ namespace NadekoBot.Modules.ClashOfClans
return;
}
List<ClashWar> wars;
if (!ClashWars.TryGetValue(Context.Guild.Id, out wars))
if (!_service.ClashWars.TryGetValue(Context.Guild.Id, out wars))
{
wars = new List<ClashWar>();
if (!ClashWars.TryAdd(Context.Guild.Id, wars))
if (!_service.ClashWars.TryAdd(Context.Guild.Id, wars))
return;
}
var cw = await CreateWar(enemyClan, size, Context.Guild.Id, Context.Channel.Id);
var cw = await _service.CreateWar(enemyClan, size, Context.Guild.Id, Context.Channel.Id);
wars.Add(cw);
await ReplyErrorLocalized("war_created", cw.ShortPrint()).ConfigureAwait(false);
await ReplyErrorLocalized("war_created", _service.ShortPrint(cw)).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
@@ -113,7 +55,7 @@ namespace NadekoBot.Modules.ClashOfClans
int num = 0;
int.TryParse(number, out num);
var warsInfo = GetWarInfo(Context.Guild, num);
var warsInfo = _service.GetWarInfo(Context.Guild, num);
if (warsInfo == null)
{
await ReplyErrorLocalized("war_not_exist").ConfigureAwait(false);
@@ -123,13 +65,13 @@ namespace NadekoBot.Modules.ClashOfClans
try
{
war.Start();
await ReplyConfirmLocalized("war_started", war.ShortPrint()).ConfigureAwait(false);
await ReplyConfirmLocalized("war_started", _service.ShortPrint(war)).ConfigureAwait(false);
}
catch
{
await ReplyErrorLocalized("war_already_started", war.ShortPrint()).ConfigureAwait(false);
await ReplyErrorLocalized("war_already_started", _service.ShortPrint(war)).ConfigureAwait(false);
}
SaveWar(war);
_service.SaveWar(war);
}
[NadekoCommand, Usage, Description, Aliases]
@@ -142,7 +84,7 @@ namespace NadekoBot.Modules.ClashOfClans
{
//check if there are any wars
List<ClashWar> wars = null;
ClashWars.TryGetValue(Context.Guild.Id, out wars);
_service.ClashWars.TryGetValue(Context.Guild.Id, out wars);
if (wars == null || wars.Count == 0)
{
await ReplyErrorLocalized("no_active_wars").ConfigureAwait(false);
@@ -163,21 +105,21 @@ namespace NadekoBot.Modules.ClashOfClans
var num = 0;
int.TryParse(number, out num);
//if number is not null, print the war needed
var warsInfo = GetWarInfo(Context.Guild, num);
var warsInfo = _service.GetWarInfo(Context.Guild, num);
if (warsInfo == null)
{
await ReplyErrorLocalized("war_not_exist").ConfigureAwait(false);
return;
}
var war = warsInfo.Item1[warsInfo.Item2];
await Context.Channel.SendConfirmAsync(war.Localize("info_about_war", $"`{war.EnemyClan}` ({war.Size} v {war.Size})"), war.ToPrettyString()).ConfigureAwait(false);
await Context.Channel.SendConfirmAsync(_service.Localize(war, "info_about_war", $"`{war.EnemyClan}` ({war.Size} v {war.Size})"), _service.ToPrettyString(war)).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Claim(int number, int baseNumber, [Remainder] string other_name = null)
{
var warsInfo = GetWarInfo(Context.Guild, number);
var warsInfo = _service.GetWarInfo(Context.Guild, number);
if (warsInfo == null || warsInfo.Item1.Count == 0)
{
await ReplyErrorLocalized("war_not_exist").ConfigureAwait(false);
@@ -190,9 +132,9 @@ namespace NadekoBot.Modules.ClashOfClans
try
{
var war = warsInfo.Item1[warsInfo.Item2];
war.Call(usr, baseNumber - 1);
SaveWar(war);
await ConfirmLocalized("claimed_base", Format.Bold(usr.ToString()), baseNumber, war.ShortPrint()).ConfigureAwait(false);
_service.Call(war, usr, baseNumber - 1);
_service.SaveWar(war);
await ConfirmLocalized("claimed_base", Format.Bold(usr.ToString()), baseNumber, _service.ShortPrint(war)).ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -225,7 +167,7 @@ namespace NadekoBot.Modules.ClashOfClans
[RequireContext(ContextType.Guild)]
public async Task EndWar(int number)
{
var warsInfo = GetWarInfo(Context.Guild, number);
var warsInfo = _service.GetWarInfo(Context.Guild, number);
if (warsInfo == null)
{
await ReplyErrorLocalized("war_not_exist").ConfigureAwait(false);
@@ -233,8 +175,8 @@ namespace NadekoBot.Modules.ClashOfClans
}
var war = warsInfo.Item1[warsInfo.Item2];
war.End();
SaveWar(war);
await ReplyConfirmLocalized("war_ended", warsInfo.Item1[warsInfo.Item2].ShortPrint()).ConfigureAwait(false);
_service.SaveWar(war);
await ReplyConfirmLocalized("war_ended", _service.ShortPrint(warsInfo.Item1[warsInfo.Item2])).ConfigureAwait(false);
warsInfo.Item1.RemoveAt(warsInfo.Item2);
}
@@ -243,7 +185,7 @@ namespace NadekoBot.Modules.ClashOfClans
[RequireContext(ContextType.Guild)]
public async Task Unclaim(int number, [Remainder] string otherName = null)
{
var warsInfo = GetWarInfo(Context.Guild, number);
var warsInfo = _service.GetWarInfo(Context.Guild, number);
if (warsInfo == null || warsInfo.Item1.Count == 0)
{
await ReplyErrorLocalized("war_not_exist").ConfigureAwait(false);
@@ -256,9 +198,9 @@ namespace NadekoBot.Modules.ClashOfClans
try
{
var war = warsInfo.Item1[warsInfo.Item2];
var baseNumber = war.Uncall(usr);
SaveWar(war);
await ReplyConfirmLocalized("base_unclaimed", usr, baseNumber + 1, war.ShortPrint()).ConfigureAwait(false);
var baseNumber = _service.Uncall(war, usr);
_service.SaveWar(war);
await ReplyConfirmLocalized("base_unclaimed", usr, baseNumber + 1, _service.ShortPrint(war)).ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -268,7 +210,7 @@ namespace NadekoBot.Modules.ClashOfClans
private async Task FinishClaim(int number, int baseNumber, int stars = 3)
{
var warInfo = GetWarInfo(Context.Guild, number);
var warInfo = _service.GetWarInfo(Context.Guild, number);
if (warInfo == null || warInfo.Item1.Count == 0)
{
await ReplyErrorLocalized("war_not_exist").ConfigureAwait(false);
@@ -279,87 +221,19 @@ namespace NadekoBot.Modules.ClashOfClans
{
if (baseNumber == -1)
{
baseNumber = war.FinishClaim(Context.User.Username, stars);
SaveWar(war);
baseNumber = _service.FinishClaim(war, Context.User.Username, stars);
_service.SaveWar(war);
}
else
{
war.FinishClaim(baseNumber, stars);
_service.FinishClaim(war, baseNumber, stars);
}
await ReplyConfirmLocalized("base_destroyed", baseNumber +1, war.ShortPrint()).ConfigureAwait(false);
await ReplyConfirmLocalized("base_destroyed", baseNumber + 1, _service.ShortPrint(war)).ConfigureAwait(false);
}
catch (Exception ex)
{
await Context.Channel.SendErrorAsync($"🔰 {ex.Message}").ConfigureAwait(false);
}
}
private static Tuple<List<ClashWar>, int> GetWarInfo(IGuild guild, int num)
{
List<ClashWar> wars = null;
ClashWars.TryGetValue(guild.Id, out wars);
if (wars == null || wars.Count == 0)
{
return null;
}
// get the number of the war
else if (num < 1 || num > wars.Count)
{
return null;
}
num -= 1;
//get the actual war
return new Tuple<List<ClashWar>, int>(wars, num);
}
public static async Task<ClashWar> CreateWar(string enemyClan, int size, ulong serverId, ulong channelId)
{
var channel = NadekoBot.Client.GetGuild(serverId)?.GetTextChannel(channelId);
using (var uow = DbHandler.UnitOfWork())
{
var cw = new ClashWar
{
EnemyClan = enemyClan,
Size = size,
Bases = new List<ClashCaller>(size),
GuildId = serverId,
ChannelId = channelId,
Channel = channel,
};
cw.Bases.Capacity = size;
for (int i = 0; i < size; i++)
{
cw.Bases.Add(new ClashCaller()
{
CallUser = null,
SequenceNumber = i,
});
}
Console.WriteLine(cw.Bases.Capacity);
uow.ClashOfClans.Add(cw);
await uow.CompleteAsync();
return cw;
}
}
public static void SaveWar(ClashWar cw)
{
if (cw.WarState == ClashWar.StateOfWar.Ended)
{
using (var uow = DbHandler.UnitOfWork())
{
uow.ClashOfClans.Remove(cw);
uow.CompleteAsync();
}
return;
}
using (var uow = DbHandler.UnitOfWork())
{
uow.ClashOfClans.Update(cw);
uow.CompleteAsync();
}
}
}
}

View File

@@ -1,148 +0,0 @@
using NadekoBot.Services.Database.Models;
using System;
using System.Linq;
using System.Text;
using static NadekoBot.Services.Database.Models.ClashWar;
namespace NadekoBot.Modules.ClashOfClans
{
public static class Extensions
{
public static void ResetTime(this ClashCaller c)
{
c.TimeAdded = DateTime.UtcNow;
}
public static void Destroy(this ClashCaller c)
{
c.BaseDestroyed = true;
}
public static void End(this ClashWar cw)
{
//Ended = true;
cw.WarState = StateOfWar.Ended;
}
public static void Call(this ClashWar cw, string u, int baseNumber)
{
if (baseNumber < 0 || baseNumber >= cw.Bases.Count)
throw new ArgumentException(cw.Localize("invalid_base_number"));
if (cw.Bases[baseNumber].CallUser != null && cw.Bases[baseNumber].Stars == 3)
throw new ArgumentException(cw.Localize("base_already_claimed"));
for (var i = 0; i < cw.Bases.Count; i++)
{
if (cw.Bases[i]?.BaseDestroyed == false && cw.Bases[i]?.CallUser == u)
throw new ArgumentException(cw.Localize("claimed_other", u, i + 1));
}
var cc = cw.Bases[baseNumber];
cc.CallUser = u.Trim();
cc.TimeAdded = DateTime.UtcNow;
cc.BaseDestroyed = false;
}
public static void Start(this ClashWar cw)
{
if (cw.WarState == StateOfWar.Started)
throw new InvalidOperationException("war_already_started");
//if (Started)
// throw new InvalidOperationException();
//Started = true;
cw.WarState = StateOfWar.Started;
cw.StartedAt = DateTime.UtcNow;
foreach (var b in cw.Bases.Where(b => b.CallUser != null))
{
b.ResetTime();
}
}
public static int Uncall(this ClashWar cw, string user)
{
user = user.Trim();
for (var i = 0; i < cw.Bases.Count; i++)
{
if (cw.Bases[i]?.CallUser != user) continue;
cw.Bases[i].CallUser = null;
return i;
}
throw new InvalidOperationException(cw.Localize("not_partic"));
}
public static string ShortPrint(this ClashWar cw) =>
$"`{cw.EnemyClan}` ({cw.Size} v {cw.Size})";
public static string ToPrettyString(this ClashWar cw)
{
var sb = new StringBuilder();
if (cw.WarState == StateOfWar.Created)
sb.AppendLine("`not started`");
var twoHours = new TimeSpan(2, 0, 0);
for (var i = 0; i < cw.Bases.Count; i++)
{
if (cw.Bases[i].CallUser == null)
{
sb.AppendLine($"`{i + 1}.` ❌*{cw.Localize("not_claimed")}*");
}
else
{
if (cw.Bases[i].BaseDestroyed)
{
sb.AppendLine($"`{i + 1}.` ✅ `{cw.Bases[i].CallUser}` {new string('⭐', cw.Bases[i].Stars)}");
}
else
{
var left = (cw.WarState == StateOfWar.Started) ? twoHours - (DateTime.UtcNow - cw.Bases[i].TimeAdded) : twoHours;
if (cw.Bases[i].Stars == 3)
{
sb.AppendLine($"`{i + 1}.` ✅ `{cw.Bases[i].CallUser}` {left.Hours}h {left.Minutes}m {left.Seconds}s left");
}
else
{
sb.AppendLine($"`{i + 1}.` ✅ `{cw.Bases[i].CallUser}` {left.Hours}h {left.Minutes}m {left.Seconds}s left {new string('⭐', cw.Bases[i].Stars)} {string.Concat(Enumerable.Repeat("🔸", 3 - cw.Bases[i].Stars))}");
}
}
}
}
return sb.ToString();
}
public static int FinishClaim(this ClashWar cw, string user, int stars = 3)
{
user = user.Trim();
for (var i = 0; i < cw.Bases.Count; i++)
{
if (cw.Bases[i]?.BaseDestroyed != false || cw.Bases[i]?.CallUser != user) continue;
cw.Bases[i].BaseDestroyed = true;
cw.Bases[i].Stars = stars;
return i;
}
throw new InvalidOperationException(cw.Localize("not_partic_or_destroyed", user));
}
public static void FinishClaim(this ClashWar cw, int index, int stars = 3)
{
if (index < 0 || index > cw.Bases.Count)
throw new ArgumentOutOfRangeException(nameof(index));
var toFinish = cw.Bases[index];
if (toFinish.BaseDestroyed != false) throw new InvalidOperationException(cw.Localize("base_already_destroyed"));
if (toFinish.CallUser == null) throw new InvalidOperationException(cw.Localize("base_already_unclaimed"));
toFinish.BaseDestroyed = true;
toFinish.Stars = stars;
}
public static string Localize(this ClashWar cw, string key)
{
return NadekoTopLevelModule.GetTextStatic(key,
NadekoBot.Localization.GetCultureInfo(cw.Channel?.GuildId),
typeof(ClashOfClans).Name.ToLowerInvariant());
}
public static string Localize(this ClashWar cw, string key, params object[] replacements)
{
return string.Format(cw.Localize(key), replacements);
}
}
}

View File

@@ -17,97 +17,12 @@ namespace NadekoBot.Modules.CustomReactions
{
public static class CustomReactionExtensions
{
public static async Task<IUserMessage> Send(this CustomReaction cr, IUserMessage context)
{
var channel = cr.DmResponse ? await context.Author.CreateDMChannelAsync() : context.Channel;
CustomReactions.ReactionStats.AddOrUpdate(cr.Trigger, 1, (k, old) => ++old);
CREmbed crembed;
if (CREmbed.TryParse(cr.Response, out crembed))
{
return await channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "");
}
return await channel.SendMessageAsync(cr.ResponseWithContext(context).SanitizeMentions());
}
}
[NadekoModule("CustomReactions", ".")]
public class CustomReactions : NadekoTopLevelModule
{
private static CustomReaction[] _globalReactions = new CustomReaction[] { };
public static CustomReaction[] GlobalReactions => _globalReactions;
public static ConcurrentDictionary<ulong, CustomReaction[]> GuildReactions { get; } = new ConcurrentDictionary<ulong, CustomReaction[]>();
public static ConcurrentDictionary<string, uint> ReactionStats { get; } = new ConcurrentDictionary<string, uint>();
private new static readonly Logger _log;
static CustomReactions()
{
_log = LogManager.GetCurrentClassLogger();
var sw = Stopwatch.StartNew();
using (var uow = DbHandler.UnitOfWork())
{
var items = uow.CustomReactions.GetAll();
GuildReactions = new ConcurrentDictionary<ulong, CustomReaction[]>(items.Where(g => g.GuildId != null && g.GuildId != 0).GroupBy(k => k.GuildId.Value).ToDictionary(g => g.Key, g => g.ToArray()));
_globalReactions = items.Where(g => g.GuildId == null || g.GuildId == 0).ToArray();
}
sw.Stop();
_log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s");
}
public void ClearStats() => ReactionStats.Clear();
public static CustomReaction TryGetCustomReaction(IUserMessage umsg)
{
var channel = umsg.Channel as SocketTextChannel;
if (channel == null)
return null;
var content = umsg.Content.Trim().ToLowerInvariant();
CustomReaction[] reactions;
GuildReactions.TryGetValue(channel.Guild.Id, out reactions);
if (reactions != null && reactions.Any())
{
var rs = reactions.Where(cr =>
{
if (cr == null)
return false;
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
var trigger = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant();
return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
}).ToArray();
if (rs.Length != 0)
{
var reaction = rs[new NadekoRandom().Next(0, rs.Length)];
if (reaction != null)
{
if (reaction.Response == "-")
return null;
return reaction;
}
}
}
var grs = GlobalReactions.Where(cr =>
{
if (cr == null)
return false;
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
var trigger = cr.TriggerWithContext(umsg).Trim().ToLowerInvariant();
return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
}).ToArray();
if (grs.Length == 0)
return null;
var greaction = grs[new NadekoRandom().Next(0, grs.Length)];
return greaction;
}
[NadekoCommand, Usage, Description, Aliases]
public async Task AddCustReact(string key, [Remainder] string message)
{
@@ -131,7 +46,7 @@ namespace NadekoBot.Modules.CustomReactions
Response = message,
};
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
uow.CustomReactions.Add(cr);
@@ -309,7 +224,7 @@ namespace NadekoBot.Modules.CustomReactions
var success = false;
CustomReaction toDelete;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
toDelete = uow.CustomReactions.Get(id);
if (toDelete == null) //not found
@@ -381,7 +296,7 @@ namespace NadekoBot.Modules.CustomReactions
var setValue = reaction.DmResponse = !reaction.DmResponse;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
uow.CustomReactions.Get(id).DmResponse = setValue;
uow.Complete();
@@ -432,7 +347,7 @@ namespace NadekoBot.Modules.CustomReactions
var setValue = reaction.AutoDeleteTrigger = !reaction.AutoDeleteTrigger;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
uow.CustomReactions.Get(id).AutoDeleteTrigger = setValue;
uow.Complete();

View File

@@ -1,107 +0,0 @@
using Discord;
using Discord.WebSocket;
using NadekoBot.Extensions;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
namespace NadekoBot.Modules.CustomReactions
{
public static class Extensions
{
public static Dictionary<string, Func<IUserMessage, string, string>> responsePlaceholders = new Dictionary<string, Func<IUserMessage, string, string>>()
{
{"%target%", (ctx, trigger) => { return ctx.Content.Substring(trigger.Length).Trim().SanitizeMentions(); } }
};
public static Dictionary<string, Func<IUserMessage, string>> placeholders = new Dictionary<string, Func<IUserMessage, string>>()
{
{"%mention%", (ctx) => { return $"<@{NadekoBot.Client.CurrentUser.Id}>"; } },
{"%user%", (ctx) => { return ctx.Author.Mention; } },
{"%rnduser%", (ctx) => {
//var ch = ctx.Channel as ITextChannel;
//if(ch == null)
// return "";
//var g = ch.Guild as SocketGuild;
//if(g == null)
// return "";
//try {
// var usr = g.Users.Skip(new NadekoRandom().Next(0, g.Users.Count)).FirstOrDefault();
// return usr.Mention;
//}
//catch {
return "[%rnduser% is temp. disabled]";
//}
//var users = g.Users.ToArray();
//return users[new NadekoRandom().Next(0, users.Length-1)].Mention;
} }
//{"%rng%", (ctx) => { return new NadekoRandom().Next(0,10).ToString(); } }
};
private static readonly Regex rngRegex = new Regex("%rng(?:(?<from>(?:-)?\\d+)-(?<to>(?:-)?\\d+))?%", RegexOptions.Compiled);
private static readonly NadekoRandom rng = new NadekoRandom();
public static Dictionary<Regex, MatchEvaluator> regexPlaceholders = new Dictionary<Regex, MatchEvaluator>()
{
{ rngRegex, (match) => {
int from = 0;
int.TryParse(match.Groups["from"].ToString(), out from);
int to = 0;
int.TryParse(match.Groups["to"].ToString(), out to);
if(from == 0 && to == 0)
{
return rng.Next(0, 11).ToString();
}
if(from >= to)
return "";
return rng.Next(from,to+1).ToString();
} }
};
private static string ResolveTriggerString(this string str, IUserMessage ctx)
{
foreach (var ph in placeholders)
{
str = str.ToLowerInvariant().Replace(ph.Key, ph.Value(ctx));
}
return str;
}
private static string ResolveResponseString(this string str, IUserMessage ctx, string resolvedTrigger)
{
foreach (var ph in placeholders)
{
str = str.Replace(ph.Key.ToLowerInvariant(), ph.Value(ctx));
}
foreach (var ph in responsePlaceholders)
{
str = str.Replace(ph.Key.ToLowerInvariant(), ph.Value(ctx, resolvedTrigger));
}
foreach (var ph in regexPlaceholders)
{
str = ph.Key.Replace(str, ph.Value);
}
return str;
}
public static string TriggerWithContext(this CustomReaction cr, IUserMessage ctx)
=> cr.Trigger.ResolveTriggerString(ctx);
public static string ResponseWithContext(this CustomReaction cr, IUserMessage ctx)
=> cr.Response.ResolveResponseString(ctx, cr.Trigger.ResolveTriggerString(ctx));
}
}

View File

@@ -9,19 +9,27 @@ using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using NadekoBot.Services.Database.Models;
namespace NadekoBot.Modules.Help
{
[NadekoModule("Help", "-")]
public class Help : NadekoTopLevelModule
{
private static string helpString { get; } = NadekoBot.BotConfig.HelpString;
public static string HelpString => String.Format(helpString, NadekoBot.Credentials.ClientId, NadekoBot.ModulePrefixes[typeof(Help).Name]);
public static string DMHelpString { get; } = NadekoBot.BotConfig.DMHelpString;
public const string PatreonUrl = "https://patreon.com/nadekobot";
public const string PaypalUrl = "https://paypal.me/Kwoth";
private readonly IBotCredentials _creds;
private readonly BotConfig _config;
private readonly CommandService _cmds;
public string HelpString => String.Format(_config.HelpString, _creds.ClientId, NadekoBot.Prefix);
public string DMHelpString => _config.DMHelpString;
public Help(IBotCredentials creds, BotConfig config, CommandService cmds)
{
_creds = creds;
_config = config;
_cmds = cmds;
}
[NadekoCommand, Usage, Description, Aliases]
public async Task Modules()
@@ -30,8 +38,9 @@ namespace NadekoBot.Modules.Help
.WithFooter(efb => efb.WithText("" + GetText("modules_footer", Prefix)))
.WithTitle(GetText("list_of_modules"))
.WithDescription(string.Join("\n",
NadekoBot.CommandService.Modules.GroupBy(m => m.GetTopLevelModule())
.Where(m => !Permissions.Permissions.GlobalPermissionCommands.BlockedModules.Contains(m.Key.Name.ToLowerInvariant()))
_cmds.Modules.GroupBy(m => m.GetTopLevelModule())
//todo perms
//.Where(m => !Permissions.Permissions.GlobalPermissionCommands.BlockedModules.Contains(m.Key.Name.ToLowerInvariant()))
.Select(m => "• " + m.Key.Name)
.OrderBy(s => s)));
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
@@ -45,8 +54,9 @@ namespace NadekoBot.Modules.Help
module = module?.Trim().ToUpperInvariant();
if (string.IsNullOrWhiteSpace(module))
return;
var cmds = NadekoBot.CommandService.Commands.Where(c => c.Module.GetTopLevelModule().Name.ToUpperInvariant().StartsWith(module))
.Where(c => !Permissions.Permissions.GlobalPermissionCommands.BlockedCommands.Contains(c.Aliases.First().ToLowerInvariant()))
var cmds = _cmds.Commands.Where(c => c.Module.GetTopLevelModule().Name.ToUpperInvariant().StartsWith(module))
//todo perms
//.Where(c => !Permissions.Permissions.GlobalPermissionCommands.BlockedCommands.Contains(c.Aliases.First().ToLowerInvariant()))
.OrderBy(c => c.Aliases.First())
.Distinct(new CommandTextEqualityComparer())
.AsEnumerable();
@@ -62,36 +72,33 @@ namespace NadekoBot.Modules.Help
for (int i = 0; i < groups.Count(); i++)
{
await channel.SendTableAsync(i == 0 ? $"📃 **{GetText("list_of_commands")}**\n" : "", groups.ElementAt(i), el => $"{el.Aliases.First(),-15} {"[" + el.Aliases.Skip(1).FirstOrDefault() + "]",-8}").ConfigureAwait(false);
await channel.SendTableAsync(i == 0 ? $"📃 **{GetText("list_of_commands")}**\n" : "", groups.ElementAt(i), el => $"{Prefix + el.Aliases.First(),-15} {"[" + el.Aliases.Skip(1).FirstOrDefault() + "]",-8}").ConfigureAwait(false);
}
await ConfirmLocalized("commands_instr", Prefix).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
public async Task H([Remainder] string comToFind = null)
public async Task H([Remainder] CommandInfo com = null)
{
var channel = Context.Channel;
comToFind = comToFind?.ToLowerInvariant();
if (string.IsNullOrWhiteSpace(comToFind))
if (com == null)
{
IMessageChannel ch = channel is ITextChannel ? await ((IGuildUser)Context.User).CreateDMChannelAsync() : channel;
await ch.SendMessageAsync(HelpString).ConfigureAwait(false);
return;
}
var com = NadekoBot.CommandService.Commands.FirstOrDefault(c => c.Aliases.Select(a=>a.ToLowerInvariant()).Contains(comToFind));
if (com == null)
{
await ReplyErrorLocalized("command_not_found").ConfigureAwait(false);
return;
}
var str = string.Format("**`{0}`**", com.Aliases.First());
var str = string.Format("**`{0}`**", Prefix + com.Aliases.First());
var alias = com.Aliases.Skip(1).FirstOrDefault();
if (alias != null)
str += string.Format(" **/ `{0}`**", alias);
str += string.Format(" **/ `{0}`**", Prefix + alias);
var embed = new EmbedBuilder()
.AddField(fb => fb.WithName(str).WithValue($"{com.RealSummary()} {GetCommandRequirements(com)}").WithIsInline(true))
.AddField(fb => fb.WithName(GetText("usage")).WithValue(com.RealRemarks()).WithIsInline(false))
@@ -122,7 +129,7 @@ namespace NadekoBot.Modules.Help
var helpstr = new StringBuilder();
helpstr.AppendLine(GetText("cmdlist_donate", PatreonUrl, PaypalUrl) + "\n");
helpstr.AppendLine("##"+ GetText("table_of_contents"));
helpstr.AppendLine(string.Join("\n", NadekoBot.CommandService.Modules.Where(m => m.GetTopLevelModule().Name.ToLowerInvariant() != "help")
helpstr.AppendLine(string.Join("\n", _cmds.Modules.Where(m => m.GetTopLevelModule().Name.ToLowerInvariant() != "help")
.Select(m => m.GetTopLevelModule().Name)
.Distinct()
.OrderBy(m => m)
@@ -130,7 +137,7 @@ namespace NadekoBot.Modules.Help
.Select(m => string.Format("- [{0}](#{1})", m, m.ToLowerInvariant()))));
helpstr.AppendLine();
string lastModule = null;
foreach (var com in NadekoBot.CommandService.Commands.OrderBy(com => com.Module.GetTopLevelModule().Name).GroupBy(c => c.Aliases.First()).Select(g => g.First()))
foreach (var com in _cmds.Commands.OrderBy(com => com.Module.GetTopLevelModule().Name).GroupBy(c => c.Aliases.First()).Select(g => g.First()))
{
var module = com.Module.GetTopLevelModule();
if (module.Name != lastModule)
@@ -147,10 +154,9 @@ namespace NadekoBot.Modules.Help
lastModule = module.Name;
}
helpstr.AppendLine($"{string.Join(" ", com.Aliases.Select(a => "`" + a + "`"))} |" +
$" {string.Format(com.Summary, com.Module.GetPrefix())} {GetCommandRequirements(com)} |" +
$" {string.Format(com.Remarks, com.Module.GetPrefix())}");
$" {string.Format(com.Summary, NadekoBot.Prefix)} {GetCommandRequirements(com)} |" +
$" {string.Format(com.Remarks, NadekoBot.Prefix)}");
}
helpstr = helpstr.Replace(NadekoBot.Client.CurrentUser.Username , "@BotName");
File.WriteAllText("../../docs/Commands List.md", helpstr.ToString());
await ReplyConfirmLocalized("commandlist_regen").ConfigureAwait(false);
}

View File

@@ -1,6 +1,4 @@
using Discord.Commands;
using NadekoBot.Modules.Music.Classes;
using System.Collections.Concurrent;
using Discord.WebSocket;
using NadekoBot.Services;
using System.IO;
@@ -19,26 +17,28 @@ using NadekoBot.Services.Music;
namespace NadekoBot.Modules.Music
{
[NadekoModule("Music", "!!")]
[DontAutoLoad]
public class Music : NadekoTopLevelModule
{
private static MusicService music;
private static MusicService _music;
private readonly DiscordShardedClient _client;
private readonly IBotCredentials _creds;
private readonly IGoogleApiService _google;
private readonly DbHandler _db;
static Music()
public Music(DiscordShardedClient client, IBotCredentials creds, IGoogleApiService google,
DbHandler db, MusicService music)
{
_client = client;
_creds = creds;
_google = google;
_db = db;
_music = music;
//it can fail if its currenctly opened or doesn't exist. Either way i don't care
try { Directory.Delete(MusicDataPath, true); } catch { }
NadekoBot.Client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated;
Directory.CreateDirectory(MusicDataPath);
//todo move to service
music = NadekoBot.MusicService;
_client.UserVoiceStateUpdated += Client_UserVoiceStateUpdated;
}
private static Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState)
private Task Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState)
{
var usr = iusr as SocketGuildUser;
if (usr == null ||
@@ -46,14 +46,14 @@ namespace NadekoBot.Modules.Music
return Task.CompletedTask;
MusicPlayer player;
if ((player = music.GetPlayer(usr.Guild.Id)) == null)
if ((player = _music.GetPlayer(usr.Guild.Id)) == null)
return Task.CompletedTask;
try
{
//if bot moved
if ((player.PlaybackVoiceChannel == oldState.VoiceChannel) &&
usr.Id == NadekoBot.Client.CurrentUser.Id)
usr.Id == _client.CurrentUser.Id)
{
if (player.Paused && newState.VoiceChannel.Users.Count > 1) //unpause if there are people in the new channel
player.TogglePause();
@@ -92,7 +92,7 @@ namespace NadekoBot.Modules.Music
return Task.CompletedTask;
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return Task.CompletedTask;
if (musicPlayer.PlaybackVoiceChannel == ((IGuildUser)Context.User).VoiceChannel)
{
@@ -110,7 +110,7 @@ namespace NadekoBot.Modules.Music
public Task Stop()
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return Task.CompletedTask;
if (((IGuildUser)Context.User).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
{
@@ -125,10 +125,10 @@ namespace NadekoBot.Modules.Music
public Task Destroy()
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return Task.CompletedTask;
if (((IGuildUser)Context.User).VoiceChannel == musicPlayer.PlaybackVoiceChannel)
music.DestroyPlayer(Context.Guild.Id);
_music.DestroyPlayer(Context.Guild.Id);
return Task.CompletedTask;
@@ -139,7 +139,7 @@ namespace NadekoBot.Modules.Music
public Task Pause()
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return Task.CompletedTask;
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
return Task.CompletedTask;
@@ -153,7 +153,7 @@ namespace NadekoBot.Modules.Music
{
var channel = (ITextChannel)Context.Channel;
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
return;
@@ -173,7 +173,7 @@ namespace NadekoBot.Modules.Music
[RequireContext(ContextType.Guild)]
public async Task Queue([Remainder] string query)
{
await music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, query).ConfigureAwait(false);
await _music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, query).ConfigureAwait(false);
if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
{
Context.Message.DeleteAfter(10);
@@ -184,7 +184,7 @@ namespace NadekoBot.Modules.Music
[RequireContext(ContextType.Guild)]
public async Task SoundCloudQueue([Remainder] string query)
{
await music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, query, musicType: MusicType.Soundcloud).ConfigureAwait(false);
await _music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, query, musicType: MusicType.Soundcloud).ConfigureAwait(false);
if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
{
Context.Message.DeleteAfter(10);
@@ -197,7 +197,7 @@ namespace NadekoBot.Modules.Music
{
Song currentSong;
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
if ((currentSong = musicPlayer?.CurrentSong) == null)
{
@@ -250,7 +250,7 @@ namespace NadekoBot.Modules.Music
return embed;
};
await Context.Channel.SendPaginatedConfirmAsync(page, printAction, lastPage, false).ConfigureAwait(false);
await Context.Channel.SendPaginatedConfirmAsync(_client, page, printAction, lastPage, false).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
@@ -258,7 +258,7 @@ namespace NadekoBot.Modules.Music
public async Task NowPlaying()
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
var currentSong = musicPlayer.CurrentSong;
if (currentSong == null)
@@ -279,7 +279,7 @@ namespace NadekoBot.Modules.Music
public async Task Volume(int val)
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
return;
@@ -301,7 +301,7 @@ namespace NadekoBot.Modules.Music
await ReplyErrorLocalized("volume_input_invalid").ConfigureAwait(false);
return;
}
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
uow.GuildConfigs.For(Context.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f;
uow.Complete();
@@ -314,7 +314,7 @@ namespace NadekoBot.Modules.Music
public async Task ShufflePlaylist()
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
return;
@@ -338,13 +338,13 @@ namespace NadekoBot.Modules.Music
await ReplyErrorLocalized("must_be_in_voice").ConfigureAwait(false);
return;
}
var plId = (await NadekoBot.Google.GetPlaylistIdsByKeywordsAsync(arg).ConfigureAwait(false)).FirstOrDefault();
var plId = (await _google.GetPlaylistIdsByKeywordsAsync(arg).ConfigureAwait(false)).FirstOrDefault();
if (plId == null)
{
await ReplyErrorLocalized("no_search_results").ConfigureAwait(false);
return;
}
var ids = await NadekoBot.Google.GetPlaylistTracksAsync(plId, 500).ConfigureAwait(false);
var ids = await _google.GetPlaylistTracksAsync(plId, 500).ConfigureAwait(false);
if (!ids.Any())
{
await ReplyErrorLocalized("no_search_results").ConfigureAwait(false);
@@ -366,7 +366,7 @@ namespace NadekoBot.Modules.Music
return;
try
{
await music.QueueSong(gusr, (ITextChannel)Context.Channel, gusr.VoiceChannel, id, true).ConfigureAwait(false);
await _music.QueueSong(gusr, (ITextChannel)Context.Channel, gusr.VoiceChannel, id, true).ConfigureAwait(false);
}
catch (SongNotFoundException) { }
catch { try { cancelSource.Cancel(); } catch { } }
@@ -391,11 +391,11 @@ namespace NadekoBot.Modules.Music
using (var http = new HttpClient())
{
var scvids = JObject.Parse(await http.GetStringAsync($"http://api.soundcloud.com/resolve?url={pl}&client_id={NadekoBot.Credentials.SoundCloudClientId}").ConfigureAwait(false))["tracks"].ToObject<SoundCloudVideo[]>();
await music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, scvids[0].TrackLink).ConfigureAwait(false);
var scvids = JObject.Parse(await http.GetStringAsync($"http://api.soundcloud.com/resolve?url={pl}&client_id={_creds.SoundCloudClientId}").ConfigureAwait(false))["tracks"].ToObject<SoundCloudVideo[]>();
await _music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, scvids[0].TrackLink).ConfigureAwait(false);
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
foreach (var svideo in scvids.Skip(1))
@@ -406,7 +406,7 @@ namespace NadekoBot.Modules.Music
{
Title = svideo.FullName,
Provider = "SoundCloud",
Uri = svideo.StreamLink,
Uri = svideo.GetStreamLink(_creds),
ProviderType = MusicType.Normal,
Query = svideo.TrackLink,
}), ((IGuildUser)Context.User).Username);
@@ -433,7 +433,7 @@ namespace NadekoBot.Modules.Music
{
try
{
await music.QueueSong(gusr, (ITextChannel)Context.Channel, gusr.VoiceChannel, file.FullName, true, MusicType.Local).ConfigureAwait(false);
await _music.QueueSong(gusr, (ITextChannel)Context.Channel, gusr.VoiceChannel, file.FullName, true, MusicType.Local).ConfigureAwait(false);
}
catch (PlaylistFullException)
{
@@ -457,7 +457,7 @@ namespace NadekoBot.Modules.Music
await ReplyErrorLocalized("must_be_in_voice").ConfigureAwait(false);
return;
}
await music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, radioLink, musicType: MusicType.Radio).ConfigureAwait(false);
await _music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, radioLink, musicType: MusicType.Radio).ConfigureAwait(false);
if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
{
Context.Message.DeleteAfter(10);
@@ -473,7 +473,7 @@ namespace NadekoBot.Modules.Music
var arg = path;
if (string.IsNullOrWhiteSpace(arg))
return;
await music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, path, musicType: MusicType.Local).ConfigureAwait(false);
await _music.QueueSong(((IGuildUser)Context.User), (ITextChannel)Context.Channel, ((IGuildUser)Context.User).VoiceChannel, path, musicType: MusicType.Local).ConfigureAwait(false);
}
@@ -495,7 +495,7 @@ namespace NadekoBot.Modules.Music
public Task Remove(int num)
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return Task.CompletedTask;
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
return Task.CompletedTask;
@@ -512,7 +512,7 @@ namespace NadekoBot.Modules.Music
if (all.Trim().ToUpperInvariant() != "ALL")
return;
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
musicPlayer.ClearQueue();
await ReplyConfirmLocalized("queue_cleared").ConfigureAwait(false);
@@ -526,7 +526,7 @@ namespace NadekoBot.Modules.Music
return;
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
fromto = fromto?.Trim();
@@ -569,7 +569,7 @@ namespace NadekoBot.Modules.Music
public async Task SetMaxQueue(uint size = 0)
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
musicPlayer.MaxQueueSize = size;
@@ -589,7 +589,7 @@ namespace NadekoBot.Modules.Music
var channel = (ITextChannel)Context.Channel;
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
musicPlayer.MaxPlaytimeSeconds = seconds;
if (seconds == 0)
@@ -603,7 +603,7 @@ namespace NadekoBot.Modules.Music
public async Task ReptCurSong()
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
var currentSong = musicPlayer.CurrentSong;
if (currentSong == null)
@@ -626,7 +626,7 @@ namespace NadekoBot.Modules.Music
public async Task RepeatPl()
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
var currentValue = musicPlayer.ToggleRepeatPlaylist();
if(currentValue)
@@ -640,7 +640,7 @@ namespace NadekoBot.Modules.Music
public async Task Save([Remainder] string name)
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
var curSong = musicPlayer.CurrentSong;
@@ -655,7 +655,7 @@ namespace NadekoBot.Modules.Music
}).ToList();
MusicPlaylist playlist;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
playlist = new MusicPlaylist
{
@@ -679,7 +679,7 @@ namespace NadekoBot.Modules.Music
public async Task Load([Remainder] int id)
{
MusicPlaylist mpl;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
mpl = uow.MusicPlaylists.GetWithSongs(id);
}
@@ -696,7 +696,7 @@ namespace NadekoBot.Modules.Music
var usr = (IGuildUser)Context.User;
try
{
await music.QueueSong(usr, (ITextChannel)Context.Channel, usr.VoiceChannel, item.Query, true, item.ProviderType).ConfigureAwait(false);
await _music.QueueSong(usr, (ITextChannel)Context.Channel, usr.VoiceChannel, item.Query, true, item.ProviderType).ConfigureAwait(false);
}
catch (SongNotFoundException) { }
catch { break; }
@@ -714,7 +714,7 @@ namespace NadekoBot.Modules.Music
List<MusicPlaylist> playlists;
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num);
}
@@ -735,13 +735,13 @@ namespace NadekoBot.Modules.Music
var success = false;
try
{
using (var uow = DbHandler.UnitOfWork())
using (var uow = _db.UnitOfWork)
{
var pl = uow.MusicPlaylists.Get(id);
if (pl != null)
{
if (NadekoBot.Credentials.IsOwner(Context.User) || pl.AuthorId == Context.User.Id)
if (_creds.IsOwner(Context.User) || pl.AuthorId == Context.User.Id)
{
uow.MusicPlaylists.Remove(pl);
await uow.CompleteAsync().ConfigureAwait(false);
@@ -766,7 +766,7 @@ namespace NadekoBot.Modules.Music
public async Task Goto(int time)
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel)
return;
@@ -801,7 +801,7 @@ namespace NadekoBot.Modules.Music
public async Task Autoplay()
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
return;
if (!musicPlayer.ToggleAutoplay())
@@ -816,7 +816,7 @@ namespace NadekoBot.Modules.Music
public async Task SetMusicChannel()
{
MusicPlayer musicPlayer;
if ((musicPlayer = music.GetPlayer(Context.Guild.Id)) == null)
if ((musicPlayer = _music.GetPlayer(Context.Guild.Id)) == null)
{
await ReplyErrorLocalized("no_player").ConfigureAwait(false);
return;

View File

@@ -15,7 +15,6 @@ using NadekoBot.Services.Searches;
namespace NadekoBot.Modules.NSFW
{
[NadekoModule("NSFW")]
public class NSFW : NadekoTopLevelModule
{
private static readonly ConcurrentDictionary<ulong, Timer> _autoHentaiTimers = new ConcurrentDictionary<ulong, Timer>();

View File

@@ -17,7 +17,6 @@ namespace NadekoBot.Modules
public readonly string ModuleTypeName;
public readonly string LowerModuleTypeName;
//todo :thinking:
public NadekoStrings _strings { get; set; }
public ILocalization _localization { get; set; }

View File

@@ -20,7 +20,6 @@ using System.Diagnostics;
namespace NadekoBot.Modules.Utility
{
[NadekoModule("Utility")]
public partial class Utility : NadekoTopLevelModule
{
private static ConcurrentDictionary<ulong, Timer> _rotatingRoleColors = new ConcurrentDictionary<ulong, Timer>();