Refactored Music, NFW, Search, Trello, ClashOfClans Modules ...
This commit is contained in:
parent
eb90bb5bd1
commit
4bc7ec9d47
@ -1,8 +1,8 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules;
|
||||
using NadekoBot.Modules.Administration.Commands;
|
||||
using NadekoBot.Modules.Music;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@ -139,7 +139,7 @@ namespace NadekoBot
|
||||
public Task LoadStats() =>
|
||||
Task.Run(() =>
|
||||
{
|
||||
var songs = Music.MusicPlayers.Count(mp => mp.Value.CurrentSong != null);
|
||||
var songs = MusicModule.MusicPlayers.Count(mp => mp.Value.CurrentSong != null);
|
||||
var sb = new System.Text.StringBuilder();
|
||||
sb.AppendLine("`Author: Kwoth` `Library: Discord.Net`");
|
||||
sb.AppendLine($"`Bot Version: {BotVersion}`");
|
||||
@ -154,7 +154,7 @@ namespace NadekoBot
|
||||
sb.AppendLine($"`Message queue size: {NadekoBot.Client.MessageQueue.Count}`");
|
||||
sb.Append($"`Greeted {ServerGreetCommand.Greeted} times.`");
|
||||
sb.AppendLine($" `| Playing {songs} songs, ".SnPl(songs) +
|
||||
$"{Music.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count)} queued.`");
|
||||
$"{MusicModule.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count)} queued.`");
|
||||
sb.AppendLine($"`Heap: {Heap(false)}`");
|
||||
statsCache = sb.ToString();
|
||||
});
|
||||
|
@ -2,6 +2,7 @@
|
||||
using NadekoBot.Classes.JSONModels;
|
||||
using NadekoBot.Commands;
|
||||
using NadekoBot.Modules.Games.Commands;
|
||||
using NadekoBot.Modules.Music;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -20,10 +21,10 @@ namespace NadekoBot.Modules.Administration.Commands
|
||||
{"%servers%", () => NadekoBot.Client.Servers.Count().ToString()},
|
||||
{"%users%", () => NadekoBot.Client.Servers.SelectMany(s => s.Users).Count().ToString()},
|
||||
{"%playing%", () => {
|
||||
var cnt = Music.MusicPlayers.Count(kvp => kvp.Value.CurrentSong != null);
|
||||
var cnt = MusicModule.MusicPlayers.Count(kvp => kvp.Value.CurrentSong != null);
|
||||
if (cnt != 1) return cnt.ToString();
|
||||
try {
|
||||
var mp = Music.MusicPlayers.FirstOrDefault();
|
||||
var mp = MusicModule.MusicPlayers.FirstOrDefault();
|
||||
return mp.Value.CurrentSong.SongInfo.Title;
|
||||
}
|
||||
catch {
|
||||
@ -31,7 +32,7 @@ namespace NadekoBot.Modules.Administration.Commands
|
||||
}
|
||||
}
|
||||
},
|
||||
{"%queued%", () => Music.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count).ToString()},
|
||||
{"%queued%", () => MusicModule.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count).ToString()},
|
||||
{"%trivia%", () => Trivia.RunningTrivias.Count.ToString()}
|
||||
};
|
||||
|
||||
|
@ -1,15 +1,14 @@
|
||||
using Discord.Commands;
|
||||
using Discord.Modules;
|
||||
using NadekoBot.Classes.ClashOfClans;
|
||||
using NadekoBot.Modules;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace NadekoBot.Commands
|
||||
namespace NadekoBot.Modules.ClashOfClans
|
||||
{
|
||||
internal class ClashOfClans : DiscordModule
|
||||
internal class ClashOfClansModule : DiscordModule
|
||||
{
|
||||
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.ClashOfClans;
|
||||
|
@ -6,10 +6,10 @@ using System.Linq;
|
||||
|
||||
namespace NadekoBot.Modules.Help
|
||||
{
|
||||
internal class Help : DiscordModule
|
||||
internal class HelpModule : DiscordModule
|
||||
{
|
||||
|
||||
public Help()
|
||||
public HelpModule()
|
||||
{
|
||||
commands.Add(new HelpCommand(this));
|
||||
}
|
@ -13,15 +13,15 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules
|
||||
namespace NadekoBot.Modules.Music
|
||||
{
|
||||
internal class Music : DiscordModule
|
||||
internal class MusicModule : DiscordModule
|
||||
{
|
||||
|
||||
public static ConcurrentDictionary<Server, MusicPlayer> MusicPlayers = new ConcurrentDictionary<Server, MusicPlayer>();
|
||||
public static ConcurrentDictionary<ulong, float> DefaultMusicVolumes = new ConcurrentDictionary<ulong, float>();
|
||||
|
||||
public Music()
|
||||
public MusicModule()
|
||||
{
|
||||
// ready for 1.0
|
||||
//NadekoBot.Client.UserUpdated += (s, e) =>
|
@ -4,9 +4,9 @@ using NadekoBot.Classes;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
|
||||
namespace NadekoBot.Modules
|
||||
namespace NadekoBot.Modules.NSFW
|
||||
{
|
||||
internal class NSFW : DiscordModule
|
||||
internal class NSFWModule : DiscordModule
|
||||
{
|
||||
|
||||
private readonly Random rng = new Random();
|
@ -306,7 +306,7 @@ Assists: {general["assists"]} Ban: {general["banRate"]}%
|
||||
|
||||
await e.Channel.SendMessage(sb.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
await e.Channel.SendMessage($":anger: Fail: Champion.gg didsabled ban data until next patch. Sorry for the inconvenience.");
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ using System.Net;
|
||||
|
||||
namespace NadekoBot.Modules.Searches
|
||||
{
|
||||
internal class Searches : DiscordModule
|
||||
internal class SearchesModule : DiscordModule
|
||||
{
|
||||
private readonly Random rng;
|
||||
public Searches()
|
||||
public SearchesModule()
|
||||
{
|
||||
commands.Add(new LoLCommands(this));
|
||||
commands.Add(new StreamNotifications(this));
|
@ -1,19 +1,22 @@
|
||||
using System;
|
||||
using Discord.Modules;
|
||||
using Manatee.Trello;
|
||||
using Manatee.Trello.ManateeJson;
|
||||
using NadekoBot.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Discord.Modules;
|
||||
using Manatee.Trello.ManateeJson;
|
||||
using Manatee.Trello;
|
||||
using System.Timers;
|
||||
using NadekoBot.Extensions;
|
||||
using Action = Manatee.Trello.Action;
|
||||
|
||||
namespace NadekoBot.Modules {
|
||||
internal class Trello : DiscordModule {
|
||||
namespace NadekoBot.Modules.Trello
|
||||
{
|
||||
internal class TrelloModule : DiscordModule
|
||||
{
|
||||
private readonly Timer t = new Timer { Interval = 2000 };
|
||||
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Trello;
|
||||
|
||||
public override void Install(ModuleManager manager) {
|
||||
public override void Install(ModuleManager manager)
|
||||
{
|
||||
|
||||
var client = manager.Client;
|
||||
|
||||
@ -29,8 +32,10 @@ namespace NadekoBot.Modules {
|
||||
Board board = null;
|
||||
|
||||
List<string> last5ActionIDs = null;
|
||||
t.Elapsed += async (s, e) => {
|
||||
try {
|
||||
t.Elapsed += async (s, e) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (board == null || bound == null)
|
||||
return; //do nothing if there is no bound board
|
||||
|
||||
@ -38,22 +43,27 @@ namespace NadekoBot.Modules {
|
||||
var cur5Actions = board.Actions.Take(board.Actions.Count() < 5 ? board.Actions.Count() : 5);
|
||||
var cur5ActionsArray = cur5Actions as Action[] ?? cur5Actions.ToArray();
|
||||
|
||||
if (last5ActionIDs == null) {
|
||||
if (last5ActionIDs == null)
|
||||
{
|
||||
last5ActionIDs = cur5ActionsArray.Select(a => a.Id).ToList();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var a in cur5ActionsArray.Where(ca => !last5ActionIDs.Contains(ca.Id))) {
|
||||
foreach (var a in cur5ActionsArray.Where(ca => !last5ActionIDs.Contains(ca.Id)))
|
||||
{
|
||||
await bound.Send("**--TRELLO NOTIFICATION--**\n" + a.ToString());
|
||||
}
|
||||
last5ActionIDs.Clear();
|
||||
last5ActionIDs.AddRange(cur5ActionsArray.Select(a => a.Id));
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Timer failed " + ex.ToString());
|
||||
}
|
||||
};
|
||||
|
||||
manager.CreateCommands("trello ", cgb => {
|
||||
manager.CreateCommands("trello ", cgb =>
|
||||
{
|
||||
|
||||
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
|
||||
|
||||
@ -61,11 +71,15 @@ namespace NadekoBot.Modules {
|
||||
.Alias("j")
|
||||
.Description("Joins a server")
|
||||
.Parameter("code", Discord.Commands.ParameterType.Required)
|
||||
.Do(async e => {
|
||||
.Do(async e =>
|
||||
{
|
||||
if (!NadekoBot.IsOwner(e.User.Id)) return;
|
||||
try {
|
||||
try
|
||||
{
|
||||
await (await client.GetInvite(e.GetArg("code"))).Accept();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
});
|
||||
@ -75,23 +89,28 @@ namespace NadekoBot.Modules {
|
||||
"You will receive notifications from your board when something is added or edited." +
|
||||
"\n**Usage**: bind [board_id]")
|
||||
.Parameter("board_id", Discord.Commands.ParameterType.Required)
|
||||
.Do(async e => {
|
||||
.Do(async e =>
|
||||
{
|
||||
if (!NadekoBot.IsOwner(e.User.Id)) return;
|
||||
if (bound != null) return;
|
||||
try {
|
||||
try
|
||||
{
|
||||
bound = e.Channel;
|
||||
board = new Board(e.GetArg("board_id").Trim());
|
||||
board.Refresh();
|
||||
await e.Channel.SendMessage("Successfully bound to this channel and board " + board.Name);
|
||||
t.Start();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Failed to join the board. " + ex.ToString());
|
||||
}
|
||||
});
|
||||
|
||||
cgb.CreateCommand("unbind")
|
||||
.Description("Unbinds a bot from the channel and board.")
|
||||
.Do(async e => {
|
||||
.Do(async e =>
|
||||
{
|
||||
if (!NadekoBot.IsOwner(e.User.Id)) return;
|
||||
if (bound == null || bound != e.Channel) return;
|
||||
t.Stop();
|
||||
@ -104,7 +123,8 @@ namespace NadekoBot.Modules {
|
||||
cgb.CreateCommand("lists")
|
||||
.Alias("list")
|
||||
.Description("Lists all lists yo ;)")
|
||||
.Do(async e => {
|
||||
.Do(async e =>
|
||||
{
|
||||
if (!NadekoBot.IsOwner(e.User.Id)) return;
|
||||
if (bound == null || board == null || bound != e.Channel) return;
|
||||
await e.Channel.SendMessage("Lists for a board '" + board.Name + "'\n" + string.Join("\n", board.Lists.Select(l => "**• " + l.ToString() + "**")));
|
||||
@ -113,7 +133,8 @@ namespace NadekoBot.Modules {
|
||||
cgb.CreateCommand("cards")
|
||||
.Description("Lists all cards from the supplied list. You can supply either a name or an index.")
|
||||
.Parameter("list_name", Discord.Commands.ParameterType.Unparsed)
|
||||
.Do(async e => {
|
||||
.Do(async e =>
|
||||
{
|
||||
if (!NadekoBot.IsOwner(e.User.Id)) return;
|
||||
if (bound == null || board == null || bound != e.Channel || e.GetArg("list_name") == null) return;
|
||||
|
@ -3,19 +3,21 @@ using Discord.Audio;
|
||||
using Discord.Commands;
|
||||
using Discord.Modules;
|
||||
using NadekoBot.Classes.JSONModels;
|
||||
using NadekoBot.Commands;
|
||||
using NadekoBot.Commands.Help.Commands;
|
||||
using NadekoBot.Modules;
|
||||
using NadekoBot.Modules.Administration;
|
||||
using NadekoBot.Modules.ClashOfClans;
|
||||
using NadekoBot.Modules.Conversations;
|
||||
using NadekoBot.Modules.Gambling;
|
||||
using NadekoBot.Modules.Games;
|
||||
using NadekoBot.Modules.Games.Commands;
|
||||
using NadekoBot.Modules.Help;
|
||||
using NadekoBot.Modules.Music;
|
||||
using NadekoBot.Modules.NSFW;
|
||||
using NadekoBot.Modules.Permissions;
|
||||
using NadekoBot.Modules.Pokemon;
|
||||
using NadekoBot.Modules.Searches;
|
||||
using NadekoBot.Modules.Translator;
|
||||
using NadekoBot.Modules.Trello;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -170,19 +172,19 @@ namespace NadekoBot
|
||||
|
||||
//install modules
|
||||
modules.Add(new AdministrationModule(), "Administration", ModuleFilter.None);
|
||||
modules.Add(new Help(), "Help", ModuleFilter.None);
|
||||
modules.Add(new HelpModule(), "Help", ModuleFilter.None);
|
||||
modules.Add(new PermissionModule(), "Permissions", ModuleFilter.None);
|
||||
modules.Add(new Conversations(), "Conversations", ModuleFilter.None);
|
||||
modules.Add(new GamblingModule(), "Gambling", ModuleFilter.None);
|
||||
modules.Add(new GamesModule(), "Games", ModuleFilter.None);
|
||||
modules.Add(new Music(), "Music", ModuleFilter.None);
|
||||
modules.Add(new Searches(), "Searches", ModuleFilter.None);
|
||||
modules.Add(new NSFW(), "NSFW", ModuleFilter.None);
|
||||
modules.Add(new ClashOfClans(), "ClashOfClans", ModuleFilter.None);
|
||||
modules.Add(new MusicModule(), "Music", ModuleFilter.None);
|
||||
modules.Add(new SearchesModule(), "Searches", ModuleFilter.None);
|
||||
modules.Add(new NSFWModule(), "NSFW", ModuleFilter.None);
|
||||
modules.Add(new ClashOfClansModule(), "ClashOfClans", ModuleFilter.None);
|
||||
modules.Add(new PokemonModule(), "Pokegame", ModuleFilter.None);
|
||||
modules.Add(new TranslatorModule(), "Translator", ModuleFilter.None);
|
||||
if (!string.IsNullOrWhiteSpace(Creds.TrelloAppKey))
|
||||
modules.Add(new Trello(), "Trello", ModuleFilter.None);
|
||||
modules.Add(new TrelloModule(), "Trello", ModuleFilter.None);
|
||||
|
||||
//run the bot
|
||||
Client.ExecuteAndWait(async () =>
|
||||
|
@ -120,7 +120,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Classes\ClashOfClans\ClashOfClans.cs" />
|
||||
<Compile Include="Modules\ClashOfClans\ClashOfClans.cs" />
|
||||
<Compile Include="Classes\DBHandler.cs" />
|
||||
<Compile Include="Classes\FlowersHandler.cs" />
|
||||
<Compile Include="Classes\IMDB\ImdbMovie.cs" />
|
||||
@ -167,7 +167,7 @@
|
||||
<Compile Include="Modules\Administration\Commands\InfoCommands.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\Remind.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\SelfAssignedRolesCommand.cs" />
|
||||
<Compile Include="Modules\ClashOfClans.cs" />
|
||||
<Compile Include="Modules\ClashOfClans\ClashOfClansModule.cs" />
|
||||
<Compile Include="Modules\Permissions\Commands\FilterWordsCommand.cs" />
|
||||
<Compile Include="Modules\Permissions\Commands\FilterInvitesCommand.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\LogCommand.cs" />
|
||||
@ -197,22 +197,22 @@
|
||||
<Compile Include="Modules\Gambling\GamblingModule.cs" />
|
||||
<Compile Include="Modules\Games\Commands\Bomberman.cs" />
|
||||
<Compile Include="Modules\Games\GamesModule.cs" />
|
||||
<Compile Include="Modules\Help\Help.cs" />
|
||||
<Compile Include="Modules\Music.cs" />
|
||||
<Compile Include="Modules\Help\HelpModule.cs" />
|
||||
<Compile Include="Modules\Music\MusicModule.cs" />
|
||||
<Compile Include="Modules\Games\Commands\PollCommand.cs" />
|
||||
<Compile Include="Modules\NSFW.cs" />
|
||||
<Compile Include="Modules\NSFW\NSFWModule.cs" />
|
||||
<Compile Include="Modules\Permissions\PermissionsModule.cs" />
|
||||
<Compile Include="Modules\Administration\Commands\RatelimitCommand.cs" />
|
||||
<Compile Include="Modules\Pokemon\PokemonModule.cs" />
|
||||
<Compile Include="Modules\Pokemon\PokeStats.cs" />
|
||||
<Compile Include="Modules\Searches\Searches.cs" />
|
||||
<Compile Include="Modules\Searches\SearchesModule.cs" />
|
||||
<Compile Include="Modules\Searches\Commands\ConverterCommand.cs" />
|
||||
<Compile Include="Modules\Searches\Commands\RedditCommand.cs" />
|
||||
<Compile Include="Modules\Translator\Helpers\GoogleTranslator.cs" />
|
||||
<Compile Include="Modules\Translator\TranslateCommand.cs" />
|
||||
<Compile Include="Modules\Translator\TranslatorModule.cs" />
|
||||
<Compile Include="Modules\Translator\ValidLanguagesCommand.cs" />
|
||||
<Compile Include="Modules\Trello.cs" />
|
||||
<Compile Include="Modules\Trello\TrelloModule.cs" />
|
||||
<Compile Include="NadekoBot.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
|
Loading…
Reference in New Issue
Block a user