private void OnConfigurationColorCommand(BotShell bot, CommandArgs e)
        {
            if (e.Args.Length < 2)
            {
                bot.SendReply(e, "Usage: configuration color [plugin] [key]");
                return;
            }
            if (!bot.Configuration.IsRegistered(e.Args[0], e.Args[1]))
            {
                bot.SendReply(e, "No such configuration entry");
                return;
            }
            RichTextWindow window = new RichTextWindow(bot);

            window.AppendTitle();
            bool   first   = true;
            string section = e.Args[0].ToLower();
            string key     = e.Args[1].ToLower();
            string command = "configuration set " + section + " " + key + " ";

            foreach (KeyValuePair <string, string> color in this.Colors)
            {
                if (color.Value != string.Empty)
                {
                    window.AppendString("  ");
                    window.AppendBotCommandStart(command + color.Value, true);
                    window.AppendColorString(color.Value, color.Key);
                    window.AppendCommandEnd();
                    window.AppendLineBreak();
                }
                else
                {
                    if (!first)
                    {
                        window.AppendLineBreak();
                    }
                    window.AppendHeader(color.Key);
                    first = false;
                }
            }
            window.AppendLineBreak();
            window.AppendHeader("Other");
            window.AppendHighlight("To select a different color not listed above use: ");
            window.AppendLineBreak();
            window.AppendNormal("/tell " + bot.Character + " " + command + "<color hex>");
            bot.SendReply(e, "Color Selection »» ", window);
        }
Exemple #2
0
 private void OnNews(BotShell bot, CommandArgs e)
 {
     try
     {
         using (IDbCommand command = this._database.Connection.CreateCommand())
         {
             RichTextWindow window = new RichTextWindow(bot);
             window.AppendTitle();
             bool  titleSticky = false;
             bool  titleNormal = false;
             Int64 lastPost    = 0;
             command.CommandText = "SELECT [news_id], [news_name] , [news_date], [news_text], [news_icon], [news_sticky] FROM [news] ORDER BY [news_sticky] DESC, [news_date] DESC LIMIT 15";
             IDataReader reader = command.ExecuteReader();
             while (reader.Read())
             {
                 if (reader.GetInt64(2) > lastPost)
                 {
                     lastPost = reader.GetInt64(2);
                 }
                 if (reader.GetInt64(5) == 1)
                 {
                     if (!titleSticky)
                     {
                         window.AppendHeader("Sticky News Posts");
                         window.AppendLineBreak();
                         titleSticky = true;
                     }
                 }
                 else
                 {
                     if (!titleNormal)
                     {
                         window.AppendHeader("Current News Posts");
                         window.AppendLineBreak();
                         titleNormal = true;
                     }
                 }
                 window.AppendBotCommandStart("news id " + reader.GetInt64(0).ToString());
                 if (reader.GetInt64(5) == 1)
                 {
                     window.AppendImage("GFX_GUI_WINDOW_ICON_POPUP");
                 }
                 else
                 {
                     window.AppendImage(_iconList[reader.GetInt64(4)]);
                 }
                 window.AppendLinkEnd();
                 window.AppendHighlight(" " + Format.DateTime(reader.GetInt64(2), FormatStyle.Compact) + " GMT by " + reader.GetString(1));
                 window.AppendLineBreak(true);
                 window.AppendNormal(reader.GetString(3));
                 if ((reader.GetString(1) == e.Sender || bot.Users.Authorized(e.Sender, UserLevel.Admin)))
                 {
                     window.AppendLineBreak(true);
                     window.AppendNormal("[");
                     window.AppendBotCommand("Remove", "news remove " + reader.GetInt64(0));
                     window.AppendNormal("]");
                 }
                 window.AppendLineBreak(2);
             }
             if (lastPost == 0)
             {
                 bot.SendReply(e, "There's currently no news");
                 return;
             }
             else
             {
                 bot.SendReply(e, "News last edited on " + HTML.CreateColorString(bot.ColorHeaderHex, Format.DateTime(lastPost, FormatStyle.Compact)) + " »» ", window);
                 return;
             }
         }
     }
     catch
     {
         bot.SendReply(e, "Error during news fetching. Please try again later");
         return;
     }
 }
Exemple #3
0
        private void OnNewsID(BotShell bot, CommandArgs e)
        {
            double d;

            if (e.Args.Length == 0)
            {
                bot.SendReply(e, "Correct Usage: news id [id]");
                return;
            }
            if (double.TryParse(e.Args[0], System.Globalization.NumberStyles.Integer, _cultureInfo, out d) == true)
            {
                try
                {
                    using (IDbCommand command = this._database.Connection.CreateCommand())
                    {
                        command.CommandText = "SELECT [news_name], [news_sticky] FROM [news] WHERE [news_id] = " + e.Args[0];
                        IDataReader reader = command.ExecuteReader();
                        if (reader.Read())
                        {
                            if ((reader.GetString(0) == e.Sender || bot.Users.Authorized(e.Sender, UserLevel.Admin)) && e.Type == CommandType.Tell)
                            {
                                RichTextWindow window = new RichTextWindow(bot);
                                window.AppendTitle("News Options");
                                window.AppendHighlight("Sticky: ");
                                if (reader.GetInt64(1) == 1)
                                {
                                    window.AppendColorString(RichTextWindow.ColorGreen, "Enabled");
                                    window.AppendNormal(" [");
                                    window.AppendBotCommand("Disable", "news sticky " + e.Args[0] + " 0");
                                    window.AppendNormal("]");
                                }
                                else
                                {
                                    window.AppendColorString(RichTextWindow.ColorOrange, "Disabled");
                                    window.AppendNormal(" [");
                                    window.AppendBotCommand("Enable", "news sticky " + e.Args[0] + " 1");
                                    window.AppendNormal("]");
                                }
                                window.AppendLineBreak(2);

                                window.AppendHeader("Icon");
                                if (reader.GetInt64(1) == 1)
                                {
                                    window.AppendNormal("There are no icons available for sticky posts");
                                }
                                else
                                {
                                    int counter = 0;
                                    foreach (string Icon in _iconList)
                                    {
                                        window.AppendBotCommandStart("news icon " + e.Args[0] + " " + counter.ToString());
                                        window.AppendImage(Icon);
                                        window.AppendLinkEnd();
                                        window.AppendNormal(" ");
                                        counter = counter + 1;
                                    }
                                }
                                bot.SendReply(e, "News Options »» ", window);
                                return;
                            }
                            else
                            {
                                bot.SendReply(e, "You don't own this news post");
                                return;
                            }
                        }
                        else
                        {
                            bot.SendReply(e, "No such news post");
                            return;
                        }
                    }
                }
                catch
                {
                    bot.SendReply(e, "Error during news fetching. Please try again later");
                    return;
                }
            }
            bot.SendReply(e, "Invalid ID");
        }