https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115367
Revision: 115367
Author: petrb
Date: 2012-05-13 15:50:01 +0000 (Sun, 13 May 2012)
Log Message:
-----------
Fixed the bug with channel names with capitals
Inserted system info to web
New function to suppress output to channels
Modified Paths:
--------------
trunk/tools/wmib/Config.cs
trunk/tools/wmib/Core.cs
trunk/tools/wmib/DumpHtm.cs
trunk/tools/wmib/Program.cs
Modified: trunk/tools/wmib/Config.cs
===================================================================
--- trunk/tools/wmib/Config.cs 2012-05-13 15:39:13 UTC (rev 115366)
+++ trunk/tools/wmib/Config.cs 2012-05-13 15:50:01 UTC (rev 115367)
@@ -34,7 +34,9 @@
public bool feed;
public bool info;
-
+
+ public bool suppress;
+
/// <summary>
/// Keys
/// </summary>
@@ -100,6 +102,10 @@
{
info = bool.Parse(parseConfig(conf, "infodb"));
}
+ if (parseConfig(conf, "talkmode") != "")
+ {
+ suppress = bool.Parse(parseConfig(conf, "talkmode"));
+ }
}
/// <summary>
@@ -111,6 +117,7 @@
AddConfig("infodb", info.ToString());
AddConfig("logged", logged.ToString());
AddConfig("feed", feed.ToString());
+ AddConfig("talkmode", suppress.ToString ());
AddConfig("keysdb", keydb);
File.WriteAllText(variables.config + "/" + name + ".setting",
conf);
}
@@ -124,6 +131,7 @@
conf = "";
keydb = variables.config + "/" + Name + ".db";
info = true;
+ suppress = false;
feed = false;
logged = false;
name = Name;
@@ -191,7 +199,7 @@
/// <summary>
/// Load config of bot
/// </summary>
- public static void Load()
+ public static int Load()
{
try
{
@@ -199,6 +207,10 @@
{
Directory.CreateDirectory(variables.config);
}
+ if (!System.IO.File.Exists (variables.config +
"/wmib"))
+ {
+ System.IO.File.WriteAllText
(variables.config + "/wmib", "//this is configuration file for bot, you need to
fill in some stuff for it to work");
+ }
text = File.ReadAllText(variables.config + "/wmib");
foreach (string x in parseConfig(text,
"channels").Replace("\n", "").Split(','))
{
@@ -208,11 +220,28 @@
channels.Add(new channel(name));
}
}
- username = parseConfig(text, "username");
- network = parseConfig(text, "network");
- login = parseConfig(text, "nick");
- debugchan = parseConfig(text, "debug");
- password = parseConfig(text, "password");
+ username = parseConfig( text, "username" );
+ network = parseConfig( text, "network" );
+ login = parseConfig( text, "nick" );
+ debugchan = parseConfig( text, "debug" );
+ url = parseConfig( text, "web" );
+ password = parseConfig( text, "password" );
+ if (login == "")
+ {
+ Console.WriteLine ("Error there is no
username for bot");
+ return 1;
+ }
+ if (network == "")
+ {
+ Console.WriteLine ("Error irc server is
wrong" );
+ return 1;
+ }
+ if (username == "")
+ {
+ Console.WriteLine ("Error there is no
username for bot");
+ return 1;
+ }
+ return 0;
}
catch (Exception ex)
{
@@ -222,7 +251,7 @@
{
Directory.CreateDirectory(DumpDir);
}
-
+ return 0;
}
public static string text;
@@ -238,7 +267,12 @@
/// </summary>
public static string username = "wm-bot";
-
+
+ /// <summary>
+ /// Uptime
+ /// </summary>
+ public static System.DateTime UpTime;
+
public static string debugchan = null;
/// <summary>
@@ -250,7 +284,12 @@
/// Login pw
/// </summary>
public static string password = "";
-
+
+ /// <summary>
+ /// The webpages url
+ /// </summary>
+ public static string url = "";
+
/// <summary>
/// Dump
/// </summary>
Modified: trunk/tools/wmib/Core.cs
===================================================================
--- trunk/tools/wmib/Core.cs 2012-05-13 15:39:13 UTC (rev 115366)
+++ trunk/tools/wmib/Core.cs 2012-05-13 15:50:01 UTC (rev 115367)
@@ -24,6 +24,7 @@
/// Configuration directory
/// </summary>
public static readonly string config = "configuration";
+ public static readonly string prefix_logdir = "log";
}
public class misc
{
@@ -518,7 +519,7 @@
{
foreach (config.channel current in config.channels)
{
- if (current.name == name)
+ if (current.name.ToLower() == name.ToLower())
{
return current;
}
@@ -547,6 +548,10 @@
public static bool Message(string message, string channel)
{
config.channel curr = getChannel(channel);
+ if (curr.suppress)
+ {
+ return true;
+ }
wd.WriteLine("PRIVMSG " + channel + " :" + message);
chanLog(message, curr, config.username, "");
wd.Flush();
@@ -998,7 +1003,51 @@
SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name);
return;
}
-
+
+ if (message == "@suppress-off")
+ {
+ if (chan.Users.isApproved(user, host, "admin"))
+ {
+ if (!chan.suppress)
+ {
+ Message("Channel had already quiet mode disabled",
chan.name);
+ return;
+ }
+ else
+ {
+ chan.suppress = false;
+ Message("Output will be no longer suppressed now",
chan.name);
+ chan.SaveConfig();
+ config.Save();
+ return;
+ }
+ }
+ SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name);
+ return;
+ }
+
+ if (message == "@suppress-on")
+ {
+ if (chan.Users.isApproved(user, host, "admin"))
+ {
+ if (chan.suppress)
+ {
+ //Message("Channel had already quiet mode disabled",
chan.name);
+ return;
+ }
+ else
+ {
+ Message("I will not talk in here until you disable
this", chan.name);
+ chan.suppress = true;
+ chan.SaveConfig();
+ config.Save();
+ return;
+ }
+ }
+ SlowQueue.DeliverMessage(messages.PermissionDenied, chan.name);
+ return;
+ }
+
if (message == "@recentchanges-off")
{
if (chan.Users.isApproved(user, host, "admin"))
@@ -1127,7 +1176,7 @@
}
if (message == "@commands")
{
- SlowQueue.DeliverMessage("Commands: channellist, trusted,
trustadd, trustdel, infobot-off, refresh, infobot-on, drop, whoami, add,
reload, help, RC-, recentchanges-on, recentchanges-off, logon, logoff,
recentchanges-, recentchanges+, RC+", chan.name);
+ SlowQueue.DeliverMessage("Commands: channellist, trusted,
trustadd, trustdel, infobot-off, refresh, infobot-on, drop, whoami, add,
reload, suppress-off, suppress-on, help, RC-, recentchanges-on,
recentchanges-off, logon, logoff, recentchanges-, recentchanges+, RC+",
chan.name);
return;
}
}
@@ -1174,6 +1223,10 @@
private static bool ShowHelp(string parameter, string channel)
{
+ if (parameter.StartsWith ("@"))
+ {
+ parameter = parameter.Substring (1);
+ }
switch (parameter.ToLower())
{
case "trustdel":
@@ -1206,6 +1259,9 @@
case "whoami":
showInfo("whoami", "Display your current status in access
list", channel);
return false;
+ case "suppress-on":
+ showInfo ("suppress-on", "Disable
output to channel");
+ return false;
case "add":
showInfo("add", "Insert bot to a specified channel and
give you admin rights for that", channel);
return false;
@@ -1236,11 +1292,20 @@
case "rc+":
showInfo("RC+", "Create entry for feed of specified page,
example @RC+ wiki page", channel);
return false;
+ case "suppress-off":
+ showInfo ("suppress-off", "Enable
output to channel");
+ return false;
}
SlowQueue.DeliverMessage("Unknown command type @commands for a
list of all commands I know", channel);
return false;
}
-
+
+ public static string getUptime()
+ {
+ System.TimeSpan uptime = System.DateTime.Now -
config.UpTime;
+ return uptime.Days.ToString () + " days " +
uptime.Hours.ToString () + " hours since " + config.UpTime.ToString ();
+ }
+
/// <summary>
/// Connection
/// </summary>
@@ -1417,6 +1482,7 @@
disabled = true;
}
}
+
public static int Disconnect()
{
wd.Flush();
Modified: trunk/tools/wmib/DumpHtm.cs
===================================================================
--- trunk/tools/wmib/DumpHtm.cs 2012-05-13 15:39:13 UTC (rev 115366)
+++ trunk/tools/wmib/DumpHtm.cs 2012-05-13 15:50:01 UTC (rev 115367)
@@ -9,6 +9,7 @@
//GNU General Public License for more details.
using System;
+using System.Collections.Generic;
using System.IO;
using System.Threading;
@@ -40,6 +41,7 @@
chan.Keys.update = false;
}
}
+ Stat();
Thread.Sleep(320000);
}
}
@@ -116,7 +118,29 @@
{
return "<tr id=\"" + Encode(name) + "\"><td>" + Encode(name) +
"</td><td>" + Encode(value) + "</td></tr>\n";
}
-
+
+ /// <summary>
+ /// Create stat for bot
+ /// </summary>
+ public static void Stat()
+ {
+ try
+ {
+ string text = "<html><head><title>System
info</title></head><body>\n";
+ text += "<h1>System data</h1><p>List of
channels:</p>";
+ foreach (config.channel chan in config.channels)
+ {
+ text = text + "" + chan.name + "
(infobot: " + chan.info.ToString () + ", recentchanges: " + chan.feed.ToString
() + ", logs: " + chan.logged.ToString () + ")<br>\n";
+ }
+ text += "Uptime: " + irc.getUptime ();
+ text += "</body></html>";
+ File.WriteAllText(config.DumpDir +
"/systemdata.htm" , text);
+ }catch (Exception b)
+ {
+ Console.WriteLine(b.Message);
+ }
+ }
+
/// <summary>
/// Generate a dump file
/// </summary>
@@ -128,9 +152,12 @@
text = text + "<h4>Infobot</h4>\n";
text = text + "<table border=1 width=100%>\n<tr><th
width=10%>Key</th><th>Value</th></tr>\n";
Channel.Keys.locked = true;
+ List<dictionary.item> list = new
List<dictionary.item>();
+ list.AddRange(Channel.Keys.text);
+ list.Sort();
if (Channel.Keys.text.Count > 0)
{
- foreach (dictionary.item Key in Channel.Keys.text)
+ foreach (dictionary.item Key in list)
{
text += AddKey(Key.key, Key.text);
}
Modified: trunk/tools/wmib/Program.cs
===================================================================
--- trunk/tools/wmib/Program.cs 2012-05-13 15:39:13 UTC (rev 115366)
+++ trunk/tools/wmib/Program.cs 2012-05-13 15:50:01 UTC (rev 115367)
@@ -24,7 +24,11 @@
private static void Main(string[] args)
{
Log("Loading...");
- config.Load();
+ config.UpTime = System.DateTime.Now;
+ if ( config.Load() != 0)
+ {
+ return;
+ }
Log("Connecting");
irc.Connect();
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs