Various cleanup.
parent
00d1b8cb81
commit
8464c6ee6c
|
@ -5,3 +5,4 @@ data
|
|||
packages
|
||||
*.swp
|
||||
Makefile
|
||||
.idea
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: AssemblyTitle("vrobot3")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace ProjectGolan.Vrobot3
|
|||
var matchbox = Finder.Matches(str);
|
||||
if(matchbox.Count == 0) return null;
|
||||
var matches = new URI[matchbox.Count];
|
||||
for(int i = 0; i < matchbox.Count; i++)
|
||||
for(var i = 0; i < matchbox.Count; i++)
|
||||
matches[i] = FromMatch(matchbox[i]);
|
||||
return matches;
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
// Mod_Admin constructor
|
||||
//
|
||||
public Mod_Admin(Bot bot_) :
|
||||
base(bot_)
|
||||
public Mod_Admin(Bot bot) :
|
||||
base(bot)
|
||||
{
|
||||
commands["kill"] = new BotCommandStructure{
|
||||
cmd = cmdKill,
|
||||
|
@ -65,7 +65,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
public void cmdMsg(User usr, Channel channel, String msg)
|
||||
{
|
||||
String[] args = Utils.GetArguments(msg, commands["msg"].help, 2, 2);
|
||||
var args = Utils.GetArguments(msg, commands["msg"].help, 2, 2);
|
||||
bot.message(ulong.Parse(args[0]), args[1].Trim());
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
public void cmdAction(User usr, Channel channel, String msg)
|
||||
{
|
||||
String[] args = Utils.GetArguments(msg, commands["action"].help, 2, 2);
|
||||
var args = Utils.GetArguments(msg, commands["action"].help, 2, 2);
|
||||
bot.action(ulong.Parse(args[0]), args[1].Trim());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,10 +48,10 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
public void run(User usr, Channel channel, String msg)
|
||||
{
|
||||
int n = rnd.Next(min, max);
|
||||
String outp = String.Empty;
|
||||
var n = rnd.Next(min, max);
|
||||
var outp = String.Empty;
|
||||
|
||||
if(bot.serverInfo.hasColors && rnd.Next(0, 8) == 1)
|
||||
if(bot.clientInfo.hasColors && rnd.Next(0, 8) == 1)
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
String[] colors = { "04", "07", "08", "09", "12", "06" };
|
||||
|
@ -61,7 +61,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
outp += word;
|
||||
}
|
||||
else
|
||||
for(int i = 0; i < n; i++)
|
||||
for(var i = 0; i < n; i++)
|
||||
outp += word;
|
||||
|
||||
bot.reply(usr, channel, outp + final);
|
||||
|
@ -71,8 +71,8 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
// Mod_Fun constructor
|
||||
//
|
||||
public Mod_Fun(Bot bot_) :
|
||||
base(bot_)
|
||||
public Mod_Fun(Bot bot) :
|
||||
base(bot)
|
||||
{
|
||||
commands["carmack"] = new BotCommandStructure{
|
||||
cmd = new ShitpostingDevice("MM", "", 3, 20, bot).run,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// See "LICENSE" for more information.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
// Idgames search module.
|
||||
// .idgames
|
||||
//
|
||||
|
@ -26,7 +26,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
public class Mod_Idgames : IBotModule
|
||||
{
|
||||
static readonly String APIURI =
|
||||
private const String APIURI =
|
||||
"http://doomworld.com/idgames/api/api.php";
|
||||
|
||||
private Random rnd = Utils.GetRND();
|
||||
|
@ -34,8 +34,8 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
// Mod_Idgames constructor
|
||||
//
|
||||
public Mod_Idgames(Bot bot_) :
|
||||
base(bot_)
|
||||
public Mod_Idgames(Bot bot) :
|
||||
base(bot)
|
||||
{
|
||||
commands["idgames"] = new BotCommandStructure{
|
||||
cmd = cmdIdgames,
|
||||
|
@ -51,11 +51,11 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
public void cmdIdgames(User usr, Channel channel, String msg)
|
||||
{
|
||||
String[] args =
|
||||
Utils.GetArguments(msg, commands["idgames"].help, 0, 3);
|
||||
var args = Utils.GetArguments(msg, commands["idgames"].help, 0, 3);
|
||||
|
||||
switch(args.Length)
|
||||
{
|
||||
default:
|
||||
case 1:
|
||||
int id;
|
||||
if(args[0].Trim().Length == 0)
|
||||
|
@ -67,10 +67,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
break;
|
||||
case 2: idgames(usr, channel, args[0], args[1]); break;
|
||||
case 3:
|
||||
if(args[2].Trim().ToLower() == "random")
|
||||
idgames(usr, channel, args[0], args[1], "random");
|
||||
else
|
||||
idgames(usr, channel, args[0], args[1], args[2].Trim());
|
||||
idgames(usr, channel, args[0], args[1], args[2].Trim());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +79,8 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
{
|
||||
var req = WebRequest.Create("http://doomworld.com/idgames/?random")
|
||||
as HttpWebRequest;
|
||||
if(req == null) throw new CommandArgumentException("fug it borked");
|
||||
|
||||
req.Referer = "http://doomworld.com/idgames/";
|
||||
bot.message(channel,
|
||||
Discord.Format.Escape(req.GetResponse().ResponseUri.ToString()));
|
||||
|
@ -94,6 +93,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
{
|
||||
var req = WebRequest.Create(APIURI + "?action=get&id=" + id)
|
||||
as HttpWebRequest;
|
||||
if(req == null) throw new CommandArgumentException("fug it borked");
|
||||
|
||||
using(var response = req.GetResponse())
|
||||
{
|
||||
|
@ -120,9 +120,9 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
private void idgames(User usr, Channel channel, String inquiry,
|
||||
String type = "title", String pos = "1")
|
||||
{
|
||||
int ipos = 0;
|
||||
var ipos = 0;
|
||||
|
||||
if(pos != "random")
|
||||
if(pos.ToLower() != "random")
|
||||
{
|
||||
Utils.TryParse(pos, "Invalid position.", out ipos);
|
||||
|
||||
|
@ -145,8 +145,8 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
if(!validtypes.Contains(type))
|
||||
throw new CommandArgumentException("Invalid inquiry type.");
|
||||
|
||||
String uri = APIURI + "?action=search&sort=rating&query=" +
|
||||
inquiry + "&type=" + type;
|
||||
var uri = APIURI + "?action=search&sort=rating&query=" + inquiry +
|
||||
"&type=" + type;
|
||||
var req = WebRequest.Create(uri);
|
||||
Console.WriteLine("idgames query: {0}", uri);
|
||||
|
||||
|
@ -167,7 +167,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
if(pos == "random") ipos = rnd.Next(0, x_titles.Count());
|
||||
if(ipos >= x_titles.Count()) ipos = x_titles.Count() - 1;
|
||||
|
||||
String title = x_titles.ElementAtOrDefault(ipos);
|
||||
var title = x_titles.ElementAtOrDefault(ipos) ?? "invalid title";
|
||||
if(title.Trim().Length > 0) title = "[ " + title + " ] ";
|
||||
|
||||
bot.message(channel,
|
||||
|
|
|
@ -29,9 +29,8 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
public int numQuotes;
|
||||
}
|
||||
|
||||
static readonly String APIURI = "http://www.greyserv.net/qdb/q/";
|
||||
static readonly String InterfaceURI =
|
||||
"http://www.greyserv.net/qdb/interface.cgi";
|
||||
const String APIURI = "http://www.greyserv.net/qdb/q/";
|
||||
const String InterfaceURI = "http://www.greyserv.net/qdb/interface.cgi";
|
||||
private Random rnd = Utils.GetRND();
|
||||
|
||||
//
|
||||
|
@ -86,7 +85,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
else
|
||||
foreach(var ln_ in lines)
|
||||
{
|
||||
String ln = ln_.Trim();
|
||||
var ln = ln_.Trim();
|
||||
if(ln.Length > 0)
|
||||
bot.message(channel, ln);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
public class Mod_Shittalk : IBotModule
|
||||
{
|
||||
private Random rnd = Utils.GetRND();
|
||||
private readonly Random rnd = Utils.GetRND();
|
||||
|
||||
//
|
||||
// Mod_Shittalk constructor
|
||||
|
@ -49,7 +49,8 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
"%s DESERVES AN AWARD. AN AWARD FOR BEING UGLY.",
|
||||
"MAN SOMETIMES I REALLY WANT TO PUNCH %s IN THE GOD DAMN FACE",
|
||||
"THERE IS SOMETHING WRONG IN THIS CHANNEL. THAT SOMETHING IS %s.",
|
||||
"%s IS A TOTAL SCRUB", "%s IS THE CONDUCTOR OF THE JELLY TRAIN",
|
||||
"%s IS A TOTAL SCRUB",
|
||||
"%s IS THE CONDUCTOR OF THE JELLY TRAIN",
|
||||
"%s IS A THING THAT SMELLS BAD MAYBE",
|
||||
"%s IS A PILE OF FAIL",
|
||||
"%s IS NOT AS COOL AS VROBOT",
|
||||
|
@ -103,10 +104,11 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
"I AM HERE TO FIGHT THE CANCER THAT AFFLICTS US ALL. NAMELY, %s.",
|
||||
"WELP, %s IS HERE",
|
||||
"OH HAI %s",
|
||||
"marrub pls upgrade my processor i can't even count to eleventy"
|
||||
"marrub pls upgrade my processor i can't even count to eleventy",
|
||||
"THIS WAS ALL %s'S FAULT"
|
||||
};
|
||||
|
||||
String choice =
|
||||
var choice =
|
||||
shittalk[rnd.Next(shittalk.Length)].Replace("%s", usr.name);
|
||||
|
||||
if(choice.StartsWith("%m "))
|
||||
|
|
|
@ -21,13 +21,13 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
public class Mod_Utils : IBotModule
|
||||
{
|
||||
private Random rnd = Utils.GetRND();
|
||||
private readonly Random rnd = Utils.GetRND();
|
||||
|
||||
//
|
||||
// Mod_Utils constructor
|
||||
//
|
||||
public Mod_Utils(Bot bot_) :
|
||||
base(bot_)
|
||||
public Mod_Utils(Bot bot) :
|
||||
base(bot)
|
||||
{
|
||||
commands["rand"] = new BotCommandStructure{
|
||||
cmd = cmdRand,
|
||||
|
@ -43,7 +43,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
"Example: .help\n" +
|
||||
"Example: .help eightball"
|
||||
};
|
||||
|
||||
|
||||
commands["decide"] = new BotCommandStructure{
|
||||
cmd = cmdDecide,
|
||||
help = "Decides between 2 or more choices.\n" +
|
||||
|
@ -73,9 +73,8 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
public void cmdRand(User usr, Channel channel, String msg)
|
||||
{
|
||||
String[] args =
|
||||
Utils.GetArguments(msg, commands["rand"].help, 1, 2, ' ');
|
||||
Double max = 0.0, min = 0.0;
|
||||
var args = Utils.GetArguments(msg, commands["rand"].help, 1, 2, ' ');
|
||||
double max = 0.0, min = 0.0;
|
||||
|
||||
Utils.TryParse(args[0].Trim(), "Invalid maximum.", out max);
|
||||
|
||||
|
@ -103,7 +102,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
public void cmdDecide(User usr, Channel channel, String msg)
|
||||
{
|
||||
String[] args = Utils.GetArguments(msg, commands["decide"].help, 2);
|
||||
var args = Utils.GetArguments(msg, commands["decide"].help, 2);
|
||||
bot.reply(usr, channel, args[rnd.Next(args.Length)].Trim());
|
||||
}
|
||||
|
||||
|
@ -112,7 +111,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
//
|
||||
private void helpList(Channel channel, bool admin)
|
||||
{
|
||||
String outp = String.Empty;
|
||||
var outp = String.Empty;
|
||||
var en =
|
||||
from kvp in bot.cmdfuncs
|
||||
let f = kvp.Value.Item2.flags
|
||||
|
@ -144,7 +143,7 @@ namespace ProjectGolan.Vrobot3.Modules
|
|||
if(bot.cmdfuncs.ContainsKey(cmdname))
|
||||
{
|
||||
var str = bot.cmdfuncs[cmdname].Item2.help;
|
||||
if(!bot.serverInfo.hasNewlines) str.Replace("\n", " || ");
|
||||
if(!bot.clientInfo.hasNewlines) str = str.Replace("\n", " || ");
|
||||
bot.message(channel, str ?? "No help available for this command.");
|
||||
}
|
||||
else
|
||||
|
|
|
@ -40,10 +40,10 @@ namespace ProjectGolan.Vrobot3
|
|||
public BotInfo[] servers;
|
||||
}
|
||||
|
||||
private List<Bot> bots = new List<Bot>();
|
||||
private List<Thread> threads = new List<Thread>();
|
||||
public String dataDir = "../data";
|
||||
public ProgramInfo info;
|
||||
private readonly List<Bot> bots = new List<Bot>();
|
||||
private readonly List<Thread> threads = new List<Thread>();
|
||||
public String dataDir = "../data";
|
||||
public ProgramInfo info;
|
||||
|
||||
public static Program Instance;
|
||||
|
||||
|
@ -69,8 +69,8 @@ namespace ProjectGolan.Vrobot3
|
|||
|
||||
info = config.info;
|
||||
|
||||
foreach(var info in config.servers)
|
||||
threads.AddItem(new Thread(bots.AddItem(new Bot(info)).connect)).Start();
|
||||
foreach(var server in config.servers)
|
||||
threads.AddItem(new Thread(bots.AddItem(new Bot(server)).connect)).Start();
|
||||
}
|
||||
catch(Exception exc)
|
||||
{
|
||||
|
@ -91,6 +91,7 @@ namespace ProjectGolan.Vrobot3
|
|||
File.WriteAllText(dataDir + "/disconnectexcdump.txt",
|
||||
exc.ToString());
|
||||
}
|
||||
|
||||
bots.Clear();
|
||||
threads.Clear();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace ProjectGolan.Vrobot3
|
|||
public static Random GetRND()
|
||||
{
|
||||
RNDHash *= DateTime.UtcNow.ToFileTime();
|
||||
Random rnd = new Random(unchecked((int)(RNDHash & 0x7fffffff)));
|
||||
var rnd = new Random(unchecked((int)(RNDHash & 0x7fffffff)));
|
||||
RNDHash ^= 0x7f8f8f8f8f8f8f8f;
|
||||
RNDHash >>= 4;
|
||||
RNDHash += 0x7f0000007f000000;
|
||||
|
@ -58,10 +58,7 @@ namespace ProjectGolan.Vrobot3
|
|||
if(min == 1 && msg == String.Empty)
|
||||
throw new CommandArgumentException(help);
|
||||
|
||||
if(max == 0)
|
||||
split = msg.Split(splitseq);
|
||||
else
|
||||
split = msg.Split(splitseq, max);
|
||||
split = max == 0 ? msg.Split(splitseq) : msg.Split(splitseq, max);
|
||||
|
||||
if(min >= 0 && split.Length < min)
|
||||
throw new CommandArgumentException(help);
|
||||
|
@ -72,7 +69,7 @@ namespace ProjectGolan.Vrobot3
|
|||
//
|
||||
// SetRange
|
||||
//
|
||||
public static Double SetRange(Double x, Double min, Double max)
|
||||
public static double SetRange(double x, double min, double max)
|
||||
=> ((max - min) * x) + min;
|
||||
|
||||
//
|
||||
|
@ -80,15 +77,15 @@ namespace ProjectGolan.Vrobot3
|
|||
//
|
||||
public static String FuzzyRelativeDate(DateTime then, DateTime now)
|
||||
{
|
||||
TimeSpan span = now.Subtract(then);
|
||||
var span = now.Subtract(then);
|
||||
|
||||
if(span.Seconds == 0)
|
||||
return "now";
|
||||
|
||||
String denom = span.Days > 0 ? "day" :
|
||||
span.Hours > 0 ? "hour" :
|
||||
span.Minutes > 0 ? "minute" :
|
||||
"second";
|
||||
var denom = span.Days > 0 ? "day" :
|
||||
span.Hours > 0 ? "hour" :
|
||||
span.Minutes > 0 ? "minute" :
|
||||
"second";
|
||||
|
||||
int number;
|
||||
switch(denom)
|
||||
|
@ -100,8 +97,7 @@ namespace ProjectGolan.Vrobot3
|
|||
case "day": number = span.Days; break;
|
||||
}
|
||||
|
||||
return String.Format("{0} {1}{2} ago", number, denom,
|
||||
number != 1 ? "s" : String.Empty);
|
||||
return $"{number} {denom}{number != 1 ? "s" : String.Empty} ago";
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -117,11 +113,12 @@ namespace ProjectGolan.Vrobot3
|
|||
{
|
||||
try
|
||||
{
|
||||
byte[] bufp = new byte[maxsize];
|
||||
int read;
|
||||
var bufp = new byte[maxsize];
|
||||
var read = 0;
|
||||
|
||||
using(var stream = resp.GetResponseStream())
|
||||
read = stream.Read(bufp, 0, maxsize);
|
||||
if(stream != null)
|
||||
read = stream.Read(bufp, 0, maxsize);
|
||||
|
||||
return Encoding.Default.GetString(bufp, 0, read);
|
||||
}
|
||||
|
|
12
vrobot3.sln
12
vrobot3.sln
|
@ -5,14 +5,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vrobot3", "vrobot3.csproj",
|
|||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
Debug|AnyCPU = Debug|AnyCPU
|
||||
Release|AnyCPU = Release|AnyCPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{83337FF3-3334-42EC-824D-532FF0C973A9}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{83337FF3-3334-42EC-824D-532FF0C973A9}.Debug|x86.Build.0 = Debug|x86
|
||||
{83337FF3-3334-42EC-824D-532FF0C973A9}.Release|x86.ActiveCfg = Release|x86
|
||||
{83337FF3-3334-42EC-824D-532FF0C973A9}.Release|x86.Build.0 = Release|x86
|
||||
{83337FF3-3334-42EC-824D-532FF0C973A9}.Debug|AnyCPU.ActiveCfg = Debug|AnyCPU
|
||||
{83337FF3-3334-42EC-824D-532FF0C973A9}.Debug|AnyCPU.Build.0 = Debug|AnyCPU
|
||||
{83337FF3-3334-42EC-824D-532FF0C973A9}.Release|AnyCPU.ActiveCfg = Release|AnyCPU
|
||||
{83337FF3-3334-42EC-824D-532FF0C973A9}.Release|AnyCPU.Build.0 = Release|AnyCPU
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
Policies = $0
|
||||
|
|
Loading…
Reference in New Issue