public static async Task <bool> ValidateQuery(Discord.Channel ch, string query) { if (!string.IsNullOrEmpty(query.Trim())) { return(true); } await ch.Send("Please specify search parameters.").ConfigureAwait(false); return(false); }
private static async Task <bool> ValidateQuery(Discord.Channel ch, string query) { if (string.IsNullOrEmpty(query.Trim())) { await ch.Send("Please specify search parameters."); return(false); } return(true); }
public override void Install(ModuleManager manager) { var client = manager.Client; var serializer = new ManateeSerializer(); TrelloConfiguration.Serializer = serializer; TrelloConfiguration.Deserializer = serializer; TrelloConfiguration.JsonFactory = new ManateeFactory(); TrelloConfiguration.RestClientProvider = new Manatee.Trello.WebApi.WebApiClientProvider(); TrelloAuthorization.Default.AppKey = NadekoBot.TrelloAppKey; //TrelloAuthorization.Default.UserToken = "[your user token]"; Discord.Channel bound = null; Board board = null; Timer t = new Timer(); t.Interval = 2000; List <string> last5ActionIDs = null; t.Elapsed += async(s, e) => { try { if (board == null || bound == null) { return; //do nothing if there is no bound board } board.Refresh(); IEnumerable <Manatee.Trello.Action> cur5Actions; if (board.Actions.Count() < 5) { cur5Actions = board.Actions.Take(board.Actions.Count()); } else { cur5Actions = board.Actions.Take(5); } if (last5ActionIDs == null) { last5ActionIDs = new List <string>(); foreach (var a in cur5Actions) { last5ActionIDs.Add(a.Id); } return; } foreach (var a in cur5Actions.Where(ca => !last5ActionIDs.Contains(ca.Id))) { await bound.Send("**--TRELLO NOTIFICATION--**\n" + a.ToString()); } last5ActionIDs.Clear(); foreach (var a in cur5Actions) { last5ActionIDs.Add(a.Id); } } catch (Exception ex) { Console.WriteLine("Timer failed " + ex.ToString()); } }; manager.CreateCommands("", cgb => { cgb.CreateCommand("join") .Alias("j") .Description("Joins a server") .Parameter("code", Discord.Commands.ParameterType.Required) .Do(async e => { if (e.User.Id != NadekoBot.OwnerID) { return; } try { await(await client.GetInvite(e.GetArg("code"))).Accept(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }); cgb.CreateCommand("bind") .Description("Bind a trello bot to a single channel. You will receive notifications from your board when somethign is added or edited.") .Parameter("board_id", Discord.Commands.ParameterType.Required) .Do(async e => { if (e.User.Id != NadekoBot.OwnerID) { return; } if (bound != null) { return; } try { bound = e.Channel; board = new Board(e.GetArg("board_id").Trim()); board.Refresh(); await e.Send("Successfully bound to this channel and board " + board.Name); t.Start(); } 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 => { if (e.User.Id != NadekoBot.OwnerID) { return; } if (bound == null || bound != e.Channel) { return; } t.Stop(); bound = null; board = null; await e.Send("Successfully unbound trello from this channel."); }); cgb.CreateCommand("lists") .Alias("list") .Description("Lists all lists yo ;)") .Do(async e => { if (e.User.Id != NadekoBot.OwnerID) { return; } if (bound == null || board == null || bound != e.Channel) { return; } await e.Send("Lists for a board '" + board.Name + "'\n" + string.Join("\n", board.Lists.Select(l => "**• " + l.ToString() + "**"))); }); 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 => { if (e.User.Id != NadekoBot.OwnerID) { return; } if (bound == null || board == null || bound != e.Channel || e.GetArg("list_name") == null) { return; } int num; var success = int.TryParse(e.GetArg("list_name"), out num); List list = null; if (success && num <= board.Lists.Count() && num > 0) { list = board.Lists[num - 1]; } else { list = board.Lists.Where(l => l.Name == e.GetArg("list_name")).FirstOrDefault(); } if (list != null) { await e.Send("There are " + list.Cards.Count() + " cards in a **" + list.Name + "** list\n" + string.Join("\n", list.Cards.Select(c => "**• " + c.ToString() + "**"))); } else { await e.Send("No such list."); } }); }); }
public override void Install(ModuleManager manager) { var client = manager.Client; var serializer = new ManateeSerializer(); TrelloConfiguration.Serializer = serializer; TrelloConfiguration.Deserializer = serializer; TrelloConfiguration.JsonFactory = new ManateeFactory(); TrelloConfiguration.RestClientProvider = new Manatee.Trello.WebApi.WebApiClientProvider(); TrelloAuthorization.Default.AppKey = WizBot.Creds.TrelloAppKey; //TrelloAuthorization.Default.UserToken = "[your user token]"; Discord.Channel bound = null; Board board = null; List <string> last5ActionIDs = null; t.Elapsed += async(s, e) => { try { if (board == null || bound == null) { return; //do nothing if there is no bound board } board.Refresh(); var cur5Actions = board.Actions.Take(board.Actions.Count() < 5 ? board.Actions.Count() : 5); var cur5ActionsArray = cur5Actions as Action[] ?? cur5Actions.ToArray(); if (last5ActionIDs == null) { last5ActionIDs = cur5ActionsArray.Select(a => a.Id).ToList(); return; } foreach (var a in cur5ActionsArray.Where(ca => !last5ActionIDs.Contains(ca.Id))) { await bound.Send("**--TRELLO NOTIFICATION--**\n" + a.ToString()).ConfigureAwait(false); } last5ActionIDs.Clear(); last5ActionIDs.AddRange(cur5ActionsArray.Select(a => a.Id)); } catch (Exception ex) { Console.WriteLine("Timer failed " + ex.ToString()); } }; manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); cgb.CreateCommand(Prefix + "bind") .Description("Bind a trello bot to a single channel. " + "You will receive notifications from your board when something is added or edited." + $" **Bot Owner Only!**| `{Prefix}bind [board_id]`") .Parameter("board_id", Discord.Commands.ParameterType.Required) .Do(async e => { if (!WizBot.IsOwner(e.User.Id)) { return; } if (bound != null) { return; } 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) { Console.WriteLine("Failed to join the board. " + ex.ToString()); } }); cgb.CreateCommand(Prefix + "unbind") .Description($"Unbinds a bot from the channel and board. **Bot Owner Only!**| `{Prefix}unbind`") .Do(async e => { if (!WizBot.IsOwner(e.User.Id)) { return; } if (bound == null || bound != e.Channel) { return; } t.Stop(); bound = null; board = null; await e.Channel.SendMessage("Successfully unbound trello from this channel.").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "lists") .Alias(Prefix + "list") .Description($"Lists all lists, yo ;) **Bot Owner Only!**| `{Prefix}list`") .Do(async e => { if (!WizBot.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() + "**"))) .ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cards") .Description($"Lists all cards from the supplied list. You can supply either a name or an index. **Bot Owner Only!**| `{Prefix}cards index`") .Parameter("list_name", Discord.Commands.ParameterType.Unparsed) .Do(async e => { if (!WizBot.IsOwner(e.User.Id)) { return; } if (bound == null || board == null || bound != e.Channel || e.GetArg("list_name") == null) { return; } int num; var success = int.TryParse(e.GetArg("list_name"), out num); List list = null; if (success && num <= board.Lists.Count() && num > 0) { list = board.Lists[num - 1]; } else { list = board.Lists.FirstOrDefault(l => l.Name == e.GetArg("list_name")); } if (list != null) { await e.Channel.SendMessage("There are " + list.Cards.Count() + " cards in a **" + list.Name + "** list\n" + string.Join("\n", list.Cards.Select(c => "**• " + c.ToString() + "**"))) .ConfigureAwait(false); } else { await e.Channel.SendMessage("No such list.") .ConfigureAwait(false); } }); }); }
public override void Install(ModuleManager manager) { var client = manager.Client; var serializer = new ManateeSerializer(); TrelloConfiguration.Serializer = serializer; TrelloConfiguration.Deserializer = serializer; TrelloConfiguration.JsonFactory = new ManateeFactory(); TrelloConfiguration.RestClientProvider = new Manatee.Trello.WebApi.WebApiClientProvider(); TrelloAuthorization.Default.AppKey = MidnightBot.Creds.TrelloAppKey; //TrelloAuthorization.Default.UserToken = "[your user token]"; Discord.Channel bound = null; Board board = null; List <string> last5ActionIDs = null; t.Elapsed += async(s, e) => { try { if (board == null || bound == null) { return; //do nothing if there is no bound board } board.Refresh(); var cur5Actions = board.Actions.Take(board.Actions.Count() < 5 ? board.Actions.Count() : 5); var cur5ActionsArray = cur5Actions as Action[] ?? cur5Actions.ToArray(); if (last5ActionIDs == null) { last5ActionIDs = cur5ActionsArray.Select(a => a.Id).ToList(); return; } foreach (var a in cur5ActionsArray.Where(ca => !last5ActionIDs.Contains(ca.Id))) { await bound.Send("**--TRELLO NOTIFICATION--**\n" + a.ToString()).ConfigureAwait(false); } last5ActionIDs.Clear(); last5ActionIDs.AddRange(cur5ActionsArray.Select(a => a.Id)); } catch (Exception ex) { Console.WriteLine("Timer failed " + ex.ToString()); } }; manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); cgb.CreateCommand(Prefix + "bind") .Description("Bindet einen trello Bot an einen einzigen Server. " + "Du erhälst Benachrichtigungen, wenn etwas entfernt, oder hinzugefügt wird." + $" | `{Prefix}bind [board_id]`") .Parameter("board_id", Discord.Commands.ParameterType.Required) .Do(async e => { if (!MidnightBot.IsOwner(e.User.Id)) { return; } if (bound != null) { return; } try { bound = e.Channel; board = new Board(e.GetArg("board_id").Trim()); board.Refresh(); await e.Channel.SendMessage("Erfolgreich zu diesem Board und Channel gebunden " + board.Name).ConfigureAwait(false); t.Start(); } catch (Exception ex) { Console.WriteLine("Board konnte nicht beigetreten werden. " + ex.ToString()); } }); cgb.CreateCommand(Prefix + "unbind") .Description("Entknüpft einen Bot vom Channel und Board.") .Do(async e => { if (!MidnightBot.IsOwner(e.User.Id)) { return; } if (bound == null || bound != e.Channel) { return; } t.Stop(); bound = null; board = null; await e.Channel.SendMessage("Erfolgreich trello von diesem Channel entknüpft.").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "lists") .Alias(Prefix + "list") .Description("Listet alle Listen") .Do(async e => { if (!MidnightBot.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() + "**"))) .ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cards") .Description($"Lists all cards from the supplied list. You can supply either a name or an index. | `{Prefix}cards index`") .Parameter("list_name", Discord.Commands.ParameterType.Unparsed) .Do(async e => { if (!MidnightBot.IsOwner(e.User.Id)) { return; } if (bound == null || board == null || bound != e.Channel || e.GetArg("list_name") == null) { return; } int num; var success = int.TryParse(e.GetArg("list_name"), out num); List list = null; if (success && num <= board.Lists.Count() && num > 0) { list = board.Lists[num - 1]; } else { list = board.Lists.FirstOrDefault(l => l.Name == e.GetArg("list_name")); } if (list != null) { await e.Channel.SendMessage("There are " + list.Cards.Count() + " cards in a **" + list.Name + "** list\n" + string.Join("\n", list.Cards.Select(c => "**• " + c.ToString() + "**"))) .ConfigureAwait(false); } else { await e.Channel.SendMessage("No such list.").ConfigureAwait(false); } }); }); }