04-06-2012, 19:45
So yea, you might have seen him in the shoutbox already.
It's a bot that automatically responds to words that can be found in forbidden.txt
Bot can optimized in settings.ini
NOTE 'Owners' can be configured in settings.ini by the 'JariZ,barata,yomomma' format. Owners are case-sensitive.
![[Image: tZk8FxkIcL.png]](http://i.nowfollow.nl/tZk8FxkIcL.png)
![[Image: sSxtCttm9J.png]](http://i.nowfollow.nl/sSxtCttm9J.png)
Issues
Commands
Commands need to be send in a personal message to the bot
Source
Download
Shoutbot.rar (Size: 5.61 KB / Downloads: 68)
Credits
@JariZ coding
@iAegle itsmods login function
@surtek Banning the bot
It's a bot that automatically responds to words that can be found in forbidden.txt
Bot can optimized in settings.ini
NOTE 'Owners' can be configured in settings.ini by the 'JariZ,barata,yomomma' format. Owners are case-sensitive.
![[Image: tZk8FxkIcL.png]](http://i.nowfollow.nl/tZk8FxkIcL.png)
![[Image: sSxtCttm9J.png]](http://i.nowfollow.nl/sSxtCttm9J.png)
Issues
- Users with a '-' in their name are able to bypass it (because of the way it filters)
Commands
Commands need to be send in a personal message to the bot
- !say OHAI
OHAI is your message, it will just say the message. You can add smileys by changing ':' to '||'. For example /pvt 1337 !say ||foreveralone||
- !spam smileyname
Where smileyname is the smiley it will spam 20 times example: /pvt 1337 !spam nyan
- !shutdown
Turns the bot off
Source
Code:
using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace ShoutboxBot
{
class Program
{
static IniFile ini;
static string Username = "";
static string Password = "";
static bool extreme_mode = true;
static bool ignoreall = false;
static string[] words = { };
static string[] Owners = new string[]
{
};
static Hashtable Shouts = new Hashtable();
static void Shout(WebClient aa, string msg)
{
System.Collections.Specialized.NameValueCollection Data = new System.Collections.Specialized.NameValueCollection();
Data.Add("shout_data", msg.Replace("||", ":"));
byte[] dataz = aa.UploadValues("http://www.itsmods.com/forum/xmlhttp.php?action=add_shout", "POST", Data);
if (System.Text.Encoding.ASCII.GetString(dataz).Contains("success"))
{
Console.WriteLine(">>> [SHOUTBOT] " + msg);
}
else
{
Console.WriteLine("###############################\r\nFailed to post shout: " + System.Text.Encoding.ASCII.GetString(dataz) + "\r\n###############################");
}
}
static void ProcessCommand(string username, string msg, WebClient xxx)
{
if (Owners.Contains(username))
{
if (msg.StartsWith("!spam "))
{
string aaaa = "";
int r = 0;
while(r != 20)
{
r++;
aaaa += ":"+msg.Substring(6)+": ";
}
Shout(xxx, aaaa);
}
else if (msg.StartsWith("!say "))
{
Shout(xxx, msg.Substring(5));
}
else if (msg == "!shutdown")
{
Shout(xxx, "/me [OFFLINE] kthxbaai");
Environment.Exit(1);
}
}
}
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WindowHeight = Console.LargestWindowHeight;
Console.WindowWidth = Console.LargestWindowWidth;
Console.Title = "Shoutbot";
Console.WriteLine("Loading settings...");
ini = new IniFile(Environment.CurrentDirectory + "\\settings.ini");
Username = ini.IniReadValue("LOGIN", "username");
Password = ini.IniReadValue("LOGIN", "password");
Owners = ini.IniReadValue("SETTINGS", "owners").Split(new string[] { "," }, StringSplitOptions.None);
extreme_mode = Convert.ToBoolean(ini.IniReadValue("SETTINGS", "extrememode"));
ignoreall = Convert.ToBoolean(ini.IniReadValue("SETTINGS", "ignoreall"));
try
{
words = System.IO.File.ReadAllLines("forbidden.txt");
Console.WriteLine("Forbidden words loaded");
}
catch
{
Console.WriteLine("Failed opening forbidden.txt");
Thread.Sleep(-1);
}
Console.Write("Extreme mode = ");
if (extreme_mode)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("ON");
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("OFF");
}
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Ignore all = ");
if (ignoreall)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("ON");
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("OFF");
}
Console.ForegroundColor = ConsoleColor.White;
System.Collections.Specialized.NameValueCollection Data = new System.Collections.Specialized.NameValueCollection();
Data.Add("username", Username);
Data.Add("password", Password);
Data.Add("submit", "Login");
Data.Add("action", "do_login");
WebClient wb = new WebClient();
byte[] bytes = wb.UploadValues("http://itsmods.com/forum/member.php", "POST", Data);
if (System.Text.Encoding.ASCII.GetString(bytes).Contains("successfully"))
{
Console.WriteLine("Logged in");
CookieContainer cc = new CookieContainer();
string cookies = wb.ResponseHeaders["Set-Cookie"];
cc.SetCookies(new Uri("http://itsmods.com"), cookies);
WebClient xxx = new WebClient();
xxx.Headers.Add("Cookie", cc.GetCookieHeader(new Uri("http://itsmods.com")));
//Shout(xxx, "Shoutbot v1.1 ONLINE BITCHEZ, made by @JariZ | PLEASE DON'T BAN ME :awesome:");
bool firstrun = true;
while (true)
{
xxx = new WebClient();
xxx.Headers.Add("Cookie", cc.GetCookieHeader(new Uri("http://itsmods.com")));
//Shout(xxx, "[b]ShoutBot v1 initialized[/b]. Made by @\"jariz\"!");
string a = xxx.DownloadString("http://www.itsmods.com/forum/xmlhttp.php?action=show_shouts&last_id=0");
string[] shoutsraw = a.Split(new string[] { "<br />" }, StringSplitOptions.None);
int count = -1;
foreach (string x in shoutsraw.Reverse())
{
try
{
count++;
string[] shoutsep = x.Split(new string[] { "-" }, StringSplitOptions.None);
int index = 5;
int user = 1;
if (count == 0 || count == shoutsraw.Length - 1)
{
index = 9;
user = 5;
}
string text = HtmlRemoval.StripTagsCharArray(shoutsep[index]);
int id = Convert.ToInt32(shoutsep[user].Split(new string[] { "ShoutBox.promptReason(" }, StringSplitOptions.None)[1].Split(new string[] { ");\" s" }, StringSplitOptions.None)[0]);
string username = HtmlRemoval.StripTagsCharArray(shoutsep[user].Split(new string[] { "false;\" >" }, StringSplitOptions.None)[1].Split(new string[] { "</a>" }, StringSplitOptions.None)[0]);
bool pm = false;
try
{
if (shoutsep[10] == "color: #AF4300; font")
{
pm = true;
text = shoutsep[11].Substring(34 + Username.Length).Replace("</span>", "");
}
}
catch { }
if (Shouts[id] == null) // shout's not added yet
{
Shouts.Add(id, text);
Console.Write(string.Format("[{0}] ", id));
if (pm)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[PM] ");
}
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write(username + ": ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(text);
Console.ForegroundColor = ConsoleColor.White;
if (pm && !firstrun)
{
ProcessCommand(username, text, xxx);
}
if (!ignoreall && !firstrun && !pm)
{
bool forbidden = false;
if (extreme_mode)
{
foreach (string t in words)
{
if (text.ToLower().Contains(t.ToLower())) forbidden = true;
}
}
else
{
foreach (string t in words)
{
if (text.ToLower() == t.ToLower()) forbidden = true;
}
}
if (forbidden)
{
/*if (!username.ToLower().Contains("jariz"))
{*/
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("FORBIDDEN WORD!!!111");
Console.ForegroundColor = ConsoleColor.White;
Shout(xxx, "/me [AUTOMESSAGE] Please use the searchbox in the top-right corner, " + username);
/*}
else
{
Console.WriteLine("JARIZ DETECTED, SKIPPING");
}*/
}
}
}
}
catch (Exception z)
{
}
}
if (firstrun) firstrun = false;
System.Threading.Thread.Sleep(1500);
}
}
else
{
Console.WriteLine("Fail!");
}
}
}
public static class HtmlRemoval
{
/// <summary>
/// Remove HTML from string with Regex.
/// </summary>
public static string StripTagsRegex(string source)
{
return Regex.Replace(source, "<.*?>", string.Empty);
}
/// <summary>
/// Compiled regular expression for performance.
/// </summary>
static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);
/// <summary>
/// Remove HTML from string with compiled Regex.
/// </summary>
public static string StripTagsRegexCompiled(string source)
{
return _htmlRegex.Replace(source, string.Empty);
}
/// <summary>
/// Remove HTML tags from string using char array.
/// </summary>
public static string StripTagsCharArray(string source)
{
char[] array = new char[source.Length];
int arrayIndex = 0;
bool inside = false;
for (int i = 0; i < source.Length; i++)
{
char let = source[i];
if (let == '<')
{
inside = true;
continue;
}
if (let == '>')
{
inside = false;
continue;
}
if (!inside)
{
array[arrayIndex] = let;
arrayIndex++;
}
}
return new string(array, 0, arrayIndex);
}
}
public class IniFile
{
public string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,
string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);
public IniFile(string INIPath)
{
path = INIPath;
if (!System.IO.File.Exists(INIPath))
System.IO.File.Create(INIPath);
}
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp,
255, this.path);
return temp.ToString();
}
}
}Download
Shoutbot.rar (Size: 5.61 KB / Downloads: 68)
Credits
@JariZ coding
@iAegle itsmods login function
@surtek Banning the bot




![[Image: r212360a129ce9b84444093b6cd2699013a1fbn155.png]](http://roflsaurus.com/users/public/r212360a129ce9b84444093b6cd2699013a1fbn155.png)