more cleanup, 1 more commit before being prod ready

This commit is contained in:
Master Kwoth 2016-03-03 12:26:29 +01:00
parent 4c0e832463
commit 827b5bae0c
9 changed files with 31 additions and 72 deletions

View File

@ -1,10 +1,7 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Classes.JSONModels { namespace NadekoBot.Classes.JSONModels {
internal class Config { internal class LocalizedStrings {
public string[] _8BallAnswers { get; set; }
} }
} }

View File

@ -26,7 +26,6 @@ namespace NadekoBot {
private NadekoStats() { private NadekoStats() {
var commandService = NadekoBot.Client.GetService<CommandService>(); var commandService = NadekoBot.Client.GetService<CommandService>();
statsStopwatch = new Stopwatch();
statsStopwatch.Start(); statsStopwatch.Start();
commandService.CommandExecuted += StatsCollector_RanCommand; commandService.CommandExecuted += StatsCollector_RanCommand;
@ -44,16 +43,14 @@ namespace NadekoBot {
ServerCount++; ServerCount++;
TextChannelsCount += e.Server.TextChannels.Count(); TextChannelsCount += e.Server.TextChannels.Count();
VoiceChannelsCount += e.Server.VoiceChannels.Count(); VoiceChannelsCount += e.Server.VoiceChannels.Count();
} } catch { }
catch { }
}; };
NadekoBot.Client.LeftServer += (s, e) => { NadekoBot.Client.LeftServer += (s, e) => {
try { try {
ServerCount--; ServerCount--;
TextChannelsCount -= e.Server.TextChannels.Count(); TextChannelsCount -= e.Server.TextChannels.Count();
VoiceChannelsCount -= e.Server.VoiceChannels.Count(); VoiceChannelsCount -= e.Server.VoiceChannels.Count();
} } catch { }
catch { }
}; };
NadekoBot.Client.ChannelCreated += (s, e) => { NadekoBot.Client.ChannelCreated += (s, e) => {
try { try {
@ -63,8 +60,7 @@ namespace NadekoBot {
TextChannelsCount++; TextChannelsCount++;
else if (e.Channel.Type == ChannelType.Voice) else if (e.Channel.Type == ChannelType.Voice)
VoiceChannelsCount++; VoiceChannelsCount++;
} } catch { }
catch { }
}; };
NadekoBot.Client.ChannelDestroyed += (s, e) => { NadekoBot.Client.ChannelDestroyed += (s, e) => {
try { try {
@ -74,8 +70,7 @@ namespace NadekoBot {
VoiceChannelsCount++; VoiceChannelsCount++;
else if (e.Channel.Type == ChannelType.Voice) else if (e.Channel.Type == ChannelType.Voice)
VoiceChannelsCount--; VoiceChannelsCount--;
} } catch { }
catch { }
}; };
} }
@ -129,8 +124,7 @@ namespace NadekoBot {
ConnectedServers = connectedServers, ConnectedServers = connectedServers,
DateAdded = DateTime.Now DateAdded = DateTime.Now
}); });
} } catch {
catch {
Console.WriteLine("DB Exception in stats collecting."); Console.WriteLine("DB Exception in stats collecting.");
break; break;
} }
@ -142,17 +136,16 @@ namespace NadekoBot {
try { try {
commandsRan++; commandsRan++;
Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Command { Classes.DbHandler.Instance.InsertData(new Classes._DataModels.Command {
ServerId = (long) e.Server.Id, ServerId = (long)e.Server.Id,
ServerName = e.Server.Name, ServerName = e.Server.Name,
ChannelId = (long) e.Channel.Id, ChannelId = (long)e.Channel.Id,
ChannelName = e.Channel.Name, ChannelName = e.Channel.Name,
UserId = (long) e.User.Id, UserId = (long)e.User.Id,
UserName = e.User.Name, UserName = e.User.Name,
CommandName = e.Command.Text, CommandName = e.Command.Text,
DateAdded = DateTime.Now DateAdded = DateTime.Now
}); });
} } catch {
catch {
Console.WriteLine("Error in ran command DB write."); Console.WriteLine("Error in ran command DB write.");
} }
}); });

View File

@ -4,7 +4,6 @@ using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.Commands; using Discord.Commands;

View File

@ -7,7 +7,6 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Authentication; using System.Security.Authentication;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -7,13 +7,10 @@ using NadekoBot.Extensions;
using System.Threading.Tasks; using System.Threading.Tasks;
using NadekoBot.Commands; using NadekoBot.Commands;
using System.IO; using System.IO;
using System.Collections.Concurrent;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Classes.Permissions; using NadekoBot.Classes.Permissions;
using NadekoBot.Classes._DataModels; using NadekoBot.Classes._DataModels;
using Timer = System.Timers.Timer;
namespace NadekoBot.Modules { namespace NadekoBot.Modules {
internal class Administration : DiscordModule { internal class Administration : DiscordModule {
@ -178,20 +175,10 @@ namespace NadekoBot.Modules {
await usr.Server.Ban(usr); await usr.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 (Exception ex) { } }
}); catch (Exception ex) {
cgb.CreateCommand(".ub").Alias(".unban") }
.Parameter("everything", ParameterType.Unparsed)
.Description("Unbans a mentioned user.")
.Do(async e => {
try {
if (e.User.ServerPermissions.BanMembers && e.Message.MentionedUsers.Any()) {
var usr = e.Message.MentionedUsers.First();
await usr.Server.Unban(usr);
await e.Channel.SendMessage("Unbanned user " + usr.Name + " Id: " + usr.Id);
}
} catch { }
}); });
cgb.CreateCommand(".k").Alias(".kick") cgb.CreateCommand(".k").Alias(".kick")
@ -389,15 +376,6 @@ namespace NadekoBot.Modules {
var heap = Task.Run(() => NadekoStats.Instance.Heap()); var heap = Task.Run(() => NadekoStats.Instance.Heap());
await e.Channel.SendMessage($"`Heap Size:` {heap}"); await e.Channel.SendMessage($"`Heap Size:` {heap}");
}); });
/*
cgb.CreateCommand(".leaveall")
.Description("Nadeko leaves all servers **OWNER ONLY**")
.Do(e => {
if (NadekoBot.IsOwner(e.User.Id))
NadekoBot.client.Servers.ForEach(async s => { if (s.Name == e.Server.Name) return; await s.Leave(); });
});
*/
cgb.CreateCommand(".prune") cgb.CreateCommand(".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")

View File

@ -4,7 +4,6 @@ using Discord.Modules;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Timers;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;

View File

@ -6,7 +6,7 @@ using NadekoBot.Commands;
namespace NadekoBot.Modules { namespace NadekoBot.Modules {
internal class Help : DiscordModule { internal class Help : DiscordModule {
public Help() { public Help() {
commands.Add(new HelpCommand()); commands.Add(new HelpCommand());
} }
@ -27,13 +27,14 @@ namespace NadekoBot.Modules {
.Description("List all of the bot's commands from a certain module.") .Description("List all of the bot's commands from a certain module.")
.Parameter("module", ParameterType.Unparsed) .Parameter("module", ParameterType.Unparsed)
.Do(async e => { .Do(async e => {
var commands = NadekoBot.Client.GetService<CommandService>().AllCommands var cmds = NadekoBot.Client.GetService<CommandService>().AllCommands
.Where(c => c.Category.ToLower() == e.GetArg("module").Trim().ToLower()); .Where(c => c.Category.ToLower() == e.GetArg("module").Trim().ToLower());
if (commands == null || commands.Count() == 0) { var cmdsArray = cmds as Command[] ?? cmds.ToArray();
if (!cmdsArray.Any()) {
await e.Channel.SendMessage("That module does not exist."); await e.Channel.SendMessage("That module does not exist.");
return; return;
} }
await e.Channel.SendMessage("`List of commands:` \n• " + string.Join("\n• ", commands.Select(c => c.Text))); await e.Channel.SendMessage("`List of commands:` \n• " + string.Join("\n• ", cmdsArray.Select(c => c.Text)));
}); });
}); });
} }

View File

@ -6,9 +6,11 @@ using Manatee.Trello.ManateeJson;
using Manatee.Trello; using Manatee.Trello;
using System.Timers; using System.Timers;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using Action = Manatee.Trello.Action;
namespace NadekoBot.Modules { namespace NadekoBot.Modules {
internal class Trello : DiscordModule { internal class Trello : DiscordModule {
private readonly Timer t = new Timer() { Interval = 2000 };
public override void Install(ModuleManager manager) { public override void Install(ModuleManager manager) {
var client = manager.Client; var client = manager.Client;
@ -24,8 +26,6 @@ namespace NadekoBot.Modules {
Discord.Channel bound = null; Discord.Channel bound = null;
Board board = null; Board board = null;
Timer t = new Timer();
t.Interval = 2000;
List<string> last5ActionIDs = null; List<string> last5ActionIDs = null;
t.Elapsed += async (s, e) => { t.Elapsed += async (s, e) => {
try { try {
@ -33,31 +33,26 @@ namespace NadekoBot.Modules {
return; //do nothing if there is no bound board return; //do nothing if there is no bound board
board.Refresh(); board.Refresh();
IEnumerable<Manatee.Trello.Action> cur5Actions; var cur5Actions = board.Actions.Take(board.Actions.Count() < 5 ? board.Actions.Count() : 5);
if (board.Actions.Count() < 5) var cur5ActionsArray = cur5Actions as Action[] ?? cur5Actions.ToArray();
cur5Actions = board.Actions.Take(board.Actions.Count());
else
cur5Actions = board.Actions.Take(5);
if (last5ActionIDs == null) { if (last5ActionIDs == null) {
last5ActionIDs = new List<string>(); last5ActionIDs = cur5ActionsArray.Select(a => a.Id).ToList();
foreach (var a in cur5Actions)
last5ActionIDs.Add(a.Id);
return; return;
} }
foreach (var a in cur5Actions.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()); await bound.Send("**--TRELLO NOTIFICATION--**\n" + a.ToString());
} }
last5ActionIDs.Clear(); last5ActionIDs.Clear();
foreach (var a in cur5Actions) last5ActionIDs.AddRange(cur5ActionsArray.Select(a => a.Id));
last5ActionIDs.Add(a.Id);
} catch (Exception ex) { } catch (Exception ex) {
Console.WriteLine("Timer failed " + ex.ToString()); Console.WriteLine("Timer failed " + ex.ToString());
} }
}; };
manager.CreateCommands("", cgb => { manager.CreateCommands("trello ", cgb => {
cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance);
cgb.CreateCommand("join") cgb.CreateCommand("join")
@ -124,7 +119,7 @@ namespace NadekoBot.Modules {
if (success && num <= board.Lists.Count() && num > 0) if (success && num <= board.Lists.Count() && num > 0)
list = board.Lists[num - 1]; list = board.Lists[num - 1];
else else
list = board.Lists.Where(l => l.Name == e.GetArg("list_name")).FirstOrDefault(); list = board.Lists.FirstOrDefault(l => l.Name == e.GetArg("list_name"));
if (list != null) if (list != null)

View File

@ -6,11 +6,9 @@ using Discord.Commands;
using NadekoBot.Modules; using NadekoBot.Modules;
using Discord.Modules; using Discord.Modules;
using Discord.Audio; using Discord.Audio;
using System.Timers;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using NadekoBot.Classes;
using NadekoBot.Classes.JSONModels; using NadekoBot.Classes.JSONModels;
using NadekoBot.Commands; using NadekoBot.Commands;