Initial split of the modules

This commit is contained in:
Master Kwoth 2017-09-30 00:46:33 +02:00
parent cdc2c43913
commit 599245b1ca
499 changed files with 469 additions and 256 deletions

View File

@ -6,8 +6,6 @@ using Discord;
using Discord.Commands; using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules.Administration.Services;
using NadekoBot.Modules.Music.Services;
namespace NadekoBot.Common.Replacements namespace NadekoBot.Common.Replacements
{ {
@ -46,19 +44,19 @@ namespace NadekoBot.Common.Replacements
_reps.TryAdd("%sid%", () => g == null ? "DM" : g.Id.ToString()); _reps.TryAdd("%sid%", () => g == null ? "DM" : g.Id.ToString());
_reps.TryAdd("%server%", () => g == null ? "DM" : g.Name); _reps.TryAdd("%server%", () => g == null ? "DM" : g.Name);
_reps.TryAdd("%server_time%", () => //_reps.TryAdd("%server_time%", () =>
{ //{
TimeZoneInfo to = TimeZoneInfo.Local; // TimeZoneInfo to = TimeZoneInfo.Local;
if (g != null) // if (g != null)
{ // {
if (GuildTimezoneService.AllServices.TryGetValue(client.CurrentUser.Id, out var tz)) // if (GuildTimezoneService.AllServices.TryGetValue(client.CurrentUser.Id, out var tz))
to = tz.GetTimeZoneOrDefault(g.Id) ?? TimeZoneInfo.Local; // to = tz.GetTimeZoneOrDefault(g.Id) ?? TimeZoneInfo.Local;
} // }
return TimeZoneInfo.ConvertTime(DateTime.UtcNow, // return TimeZoneInfo.ConvertTime(DateTime.UtcNow,
TimeZoneInfo.Utc, // TimeZoneInfo.Utc,
to).ToString("HH:mm ") + to.StandardName.GetInitials(); // to).ToString("HH:mm ") + to.StandardName.GetInitials();
}); //});
return this; return this;
} }
@ -88,26 +86,26 @@ namespace NadekoBot.Common.Replacements
return this; return this;
} }
public ReplacementBuilder WithMusic(MusicService ms) //public ReplacementBuilder WithMusic(MusicService ms)
{ //{
_reps.TryAdd("%playing%", () => // _reps.TryAdd("%playing%", () =>
{ // {
var cnt = ms.MusicPlayers.Count(kvp => kvp.Value.Current.Current != null); // var cnt = ms.MusicPlayers.Count(kvp => kvp.Value.Current.Current != null);
if (cnt != 1) return cnt.ToString(); // if (cnt != 1) return cnt.ToString();
try // try
{ // {
var mp = ms.MusicPlayers.FirstOrDefault(); // var mp = ms.MusicPlayers.FirstOrDefault();
var title = mp.Value?.Current.Current?.Title; // var title = mp.Value?.Current.Current?.Title;
return title ?? "No songs"; // return title ?? "No songs";
} // }
catch // catch
{ // {
return "error"; // return "error";
} // }
}); // });
_reps.TryAdd("%queued%", () => ms.MusicPlayers.Sum(kvp => kvp.Value.QueueArray().Songs.Length).ToString()); // _reps.TryAdd("%queued%", () => ms.MusicPlayers.Sum(kvp => kvp.Value.QueueArray().Songs.Length).ToString());
return this; // return this;
} //}
public ReplacementBuilder WithRngRegex() public ReplacementBuilder WithRngRegex()
{ {

View File

@ -3,7 +3,7 @@ using Discord.WebSocket;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Services.Discord namespace NadekoBot.Common
{ {
public class ReactionEventWrapper : IDisposable public class ReactionEventWrapper : IDisposable
{ {

View File

@ -0,0 +1,73 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Discord.Commands;
using NadekoBot.Services;
namespace NadekoBot.Common.TypeReaders
{
public class CommandTypeReader : TypeReader
{
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services)
{
var _cmds = ((INServiceProvider)services).GetService<CommandService>();
var _cmdHandler = ((INServiceProvider)services).GetService<CommandHandler>();
input = input.ToUpperInvariant();
var prefix = _cmdHandler.GetPrefix(context.Guild);
if (!input.StartsWith(prefix.ToUpperInvariant()))
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No such command found."));
input = input.Substring(prefix.Length);
var cmd = _cmds.Commands.FirstOrDefault(c =>
c.Aliases.Select(a => a.ToUpperInvariant()).Contains(input));
if (cmd == null)
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No such command found."));
return Task.FromResult(TypeReaderResult.FromSuccess(cmd));
}
}
//todo dependency on the module
//public class CommandOrCrTypeReader : CommandTypeReader
//{
// public override async Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services)
// {
// input = input.ToUpperInvariant();
// var _crs = ((INServiceProvider)services).GetService<CustomReactionsService>();
// if (_crs.GlobalReactions.Any(x => x.Trigger.ToUpperInvariant() == input))
// {
// return TypeReaderResult.FromSuccess(new CommandOrCrInfo(input));
// }
// var guild = context.Guild;
// if (guild != null)
// {
// if (_crs.GuildReactions.TryGetValue(guild.Id, out var crs))
// {
// if (crs.Concat(_crs.GlobalReactions).Any(x => x.Trigger.ToUpperInvariant() == input))
// {
// return TypeReaderResult.FromSuccess(new CommandOrCrInfo(input));
// }
// }
// }
// var cmd = await base.Read(context, input, services);
// if (cmd.IsSuccess)
// {
// return TypeReaderResult.FromSuccess(new CommandOrCrInfo(((CommandInfo)cmd.Values.First().Value).Name));
// }
// return TypeReaderResult.FromError(CommandError.ParseFailed, "No such command or cr found.");
// }
//}
public class CommandOrCrInfo
{
public string Name { get; set; }
public CommandOrCrInfo(string input)
{
this.Name = input;
}
}
}

View File

@ -0,0 +1,40 @@
//using System;
//using System.Threading.Tasks;
//using Discord.Commands;
//using NadekoBot.Modules.Administration.Services;
//namespace NadekoBot.Common.TypeReaders
//{
// public class GuildDateTimeTypeReader : TypeReader
// {
// public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services)
// {
// var _gts = (GuildTimezoneService)services.GetService(typeof(GuildTimezoneService));
// if (!DateTime.TryParse(input, out var dt))
// return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Input string is in an incorrect format."));
// var tz = _gts.GetTimeZoneOrUtc(context.Guild.Id);
// return Task.FromResult(TypeReaderResult.FromSuccess(new GuildDateTime(tz, dt)));
// }
// }
// public class GuildDateTime
// {
// public TimeZoneInfo Timezone { get; }
// public DateTime CurrentGuildTime { get; }
// public DateTime InputTime { get; }
// public DateTime InputTimeUtc { get; }
// private GuildDateTime() { }
// public GuildDateTime(TimeZoneInfo guildTimezone, DateTime inputTime)
// {
// var now = DateTime.UtcNow;
// Timezone = guildTimezone;
// CurrentGuildTime = TimeZoneInfo.ConvertTime(now, TimeZoneInfo.Utc, Timezone);
// InputTime = inputTime;
// InputTimeUtc = TimeZoneInfo.ConvertTime(inputTime, Timezone, TimeZoneInfo.Utc);
// }
// }
//}

Some files were not shown because too many files have changed in this diff Show More