Example #1
0
        public void RemoveSnippet(object sender, AbstractSnippet snippet)
        {
            if (Snippets.Remove(snippet))
            {
                AppSettings.PutAndSave(GetKey(snippet), Snippets);

                // Notify listeners that a snippet was removed
                Listeners.ForEach(listener => listener.SnippetRemoved(sender, this, snippet));
            }
        }
Example #2
0
        public void OnDelete(object param)
        {
            if (param is Snippet == false)
            {
                return;
            }

            // todo add to undo stack
            Snippets.Remove((Snippet)param);
        }
Example #3
0
 public async Task snippets(params string[] args)
 {
     if (!HasExecutePermission)
         return;
     if (args.Length == 0)
     {
         EmbedBuilder b = new EmbedBuilder()
         {
             Title = "Ticket Snippets",
             Color = Color.DarkPurple,
             Description = "To add a snippet:\n`!snippets add <SnippetName> <SnippetValue>`\nTo Remove a snippet:\n`!snippets remove <SnippetName>`"
         };
         foreach(var snip in Snippets)
             b.AddField(snip.Key, snip.Value);
         await Context.Channel.SendMessageAsync("", false, b.Build());
     }
     else
     {
         if(args.Length >= 2)
         {
             switch (args[0].ToLower())
             {
                 case "add":
                     {
                         string snip = args[1];
                         string snipval = string.Join(' ', args.Skip(2));
                         if (!Snippets.ContainsKey(snip))
                         {
                             if(snipval.Length > 1024)
                             {
                                 await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                                 {
                                     Title = $"wOaH bUddY",
                                     Description = $"Your snippet is tooooooo long! try adding one that less than 1000 characters"
                                 }.Build());
                                 return;
                             }
                             Snippets.Add(snip, snipval);
                             Global.SaveSnippets();
                             await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                             {
                                 Title = $"Added **{snip}**",
                                 Description = $"Succesfully added **{snip}** to the snippets"
                             }.Build());
                         }
                         else
                         {
                             await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                             {
                                 Title = $"That snippet exists!",
                                 Description = $"someone already added that snippet!"
                             }.Build());
                         }
                     }
                     break;
                 case "remove":
                     {
                         string snip = args[1];
                         if (Snippets.ContainsKey(snip))
                         {
                             //remove snippet
                             Snippets.Remove(snip);
                             Global.SaveSnippets();
                             await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                             {
                                 Title = $"Removed **{snip}**",
                                 Description = $"Successfully removed the snippet {snip}",
                                 Color = Color.Green
                             }.Build());
                         }
                         else
                         {
                             await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                             {
                                 Title = "uhm.. wat?",
                                 Description = "That snippet doesnt exist, please do `!snippets` to view the current snippets!",
                                 Color = Color.Red
                             }.Build());
                             return;
                         }
                     }
                     break;
                 default:
                     {
                         await Context.Channel.SendMessageAsync("", false, new EmbedBuilder()
                         {
                             Title = "uhm.. wat?",
                             Description = "that command is unreconized :/",
                             Color = Color.Red
                         }.Build());
                     }
                     break;
             }
         }
     }
 }