-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSysInfo.cs
96 lines (76 loc) · 2.18 KB
/
SysInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Linq;
using System.Management;
using System.Text.RegularExpressions;
using MikuBot.Commands;
using MikuBot.Modules;
namespace MikuBot.ExtraPlugins
{
public class SysInfo : MsgCommandModuleBase
{
private string CollapseWhitespace(string str)
{
var res = Regex.Replace(str, @"\s{2,}", " ");
return res;
}
private string MemoryString
{
get
{
var mgmt = new ManagementClass("Win32_ComputerSystem");
var obj = mgmt.GetInstances().Cast<ManagementObject>().FirstOrDefault();
if (obj == null)
return "Unknown memory";
//var mobo = obj.Properties["Manufacturer"].Value + " " + obj.Properties["Model"].Value;
var compInfo = new Microsoft.VisualBasic.Devices.ComputerInfo();
var totalRam = long.Parse(compInfo.TotalPhysicalMemory.ToString()) / 1024 / 1024;
var freeRam = long.Parse(compInfo.AvailablePhysicalMemory.ToString()) / 1024 / 1024;
return "RAM: " + freeRam + "MB free, " + totalRam + " MB total";
}
}
private string ProcString
{
get
{
var procCount = Environment.ProcessorCount;
var procInfo = "Unknown processor";
var mgmt = new ManagementClass("Win32_Processor");
var objCol = mgmt.GetInstances().Cast<ManagementObject>().FirstOrDefault();
if (objCol != null)
{
procInfo = CollapseWhitespace(objCol.Properties["Name"].Value.ToString());
}
return procCount + "x " + procInfo;
}
}
public override int CooldownChannelMs
{
get { return 10000; }
}
public override int CooldownUserMs
{
get { return 30000; }
}
public override string CommandDescription
{
get { return "Displays information about the environement this bot is running in."; }
}
public override string Name
{
get { return "SysInfo"; }
}
public override void HandleCommand(MsgCommand chat, IBotContext bot)
{
if (!CheckCall(chat, bot))
return;
var os = Environment.OSVersion.ToString();
var clrVer = Environment.Version.ToString();
var arch = Environment.Is64BitOperatingSystem ? "x86-64" : "x86";
bot.Writer.Msg(chat.ChannelOrSenderNick,
os + " " + arch
+ " | CLR " + clrVer
+ " | " + ProcString
+ " | " + MemoryString);
}
}
}