Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using ChatSharp;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Data;
- using Microsoft.Win32;
- namespace Tim_s_IRC_bot
- {
- class Program
- {
- static void Main(string[] args)
- {
- {
- if (System.IO.File.Exists(System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemDrive"), "/TimsBot/settings.ini")))
- {
- }
- else
- {
- Console.WriteLine("Welcome to Tims IRC bot");
- Console.ReadLine();
- Console.WriteLine("WHich channel do you want the bot to join?");
- string Channel = Console.ReadLine();
- Console.WriteLine("Which nickname do you want to have?");
- string Nickname = Console.ReadLine();
- Console.WriteLine("Which username do you have?(if none just leave blank)");
- string username = Console.ReadLine();
- if (username == "") {
- username = username.Replace("", "TimsBot");
- }
- Console.WriteLine("Which password do you have for the account?(leave blank if none)");
- string password = Console.ReadLine();
- System.IO.Directory.CreateDirectory("/TimsBot/");
- System.IO.File.WriteAllText(System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemDrive"), "/TimsBot/settings.ini"),"Channel= " + Channel + Environment.NewLine + "Botname= " + Nickname + Environment.NewLine + "username= " + username + Environment.NewLine + "password= " + password);
- System.IO.File.Copy(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, "/TimsBot/TimsBot.exe");
- System.IO.File.Copy(System.IO.Path.Combine(Environment.CurrentDirectory , "ChatSharp.dll"), "/TimsBot/ChatSharp.dll");
- System.IO.File.WriteAllText("/TimsBot/tokensystem.txt", "This is the tokenSystem File" + Environment.NewLine);
- Console.Clear();
- Console.WriteLine("Install successfull, start the program.");
- Console.ReadLine();
- Environment.Exit(0);
- }
- Console.WriteLine("Connecting to Freenode");
- var handle = GetConsoleWindow();
- ShowWindow(handle, SW_HIDE);
- string NickName = System.IO.File.ReadAllText("/TimsBot/settings.ini");
- string Channel1 = System.IO.File.ReadAllText("/TimsBot/settings.ini");
- int index = NickName.IndexOf(System.Environment.NewLine);
- NickName = NickName.Substring(index + System.Environment.NewLine.Length).Replace("Botname= ", "");
- Channel1 = Channel1.Remove(Channel1.TrimEnd().LastIndexOf(Environment.NewLine)).Replace("Channel= ", "");
- var client = new IrcClient("irc.freenode.net", new IrcUser("Tim241", "Tims241", "Twanda01"));
- client.ConnectionComplete += (s, e) => client.JoinChannel("##B4A");
- Console.Clear();
- NotifyIcon trayIcon = new NotifyIcon();
- trayIcon.Text = "TimsIRCBot";
- trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);
- ContextMenu trayMenu = new ContextMenu();
- trayMenu.MenuItems.Add("exit", new EventHandler(item1_Click));
- trayIcon.ContextMenu = trayMenu;
- trayIcon.Visible = true;
- client.ChannelMessageRecieved += (s, e) =>
- {
- var channel = client.Channels[e.PrivateMessage.Source];
- if (e.PrivateMessage.Message == "!list")
- channel.SendMessage(string.Join(", ", channel.Users.Select(u => u.Nick)));
- else if (e.PrivateMessage.Message.StartsWith("!ban "))
- {
- var target = e.PrivateMessage.Message.Substring(5);
- client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname));
- channel.Kick(e.PrivateMessage.Message.Substring(5));
- Console.WriteLine(e.PrivateMessage.Message.Substring(5) + " " + "is banned");
- }
- else if (e.PrivateMessage.Message.StartsWith("!unban "))
- {
- var target = e.PrivateMessage.Message.Substring(7);
- client.WhoIs(target, whois => channel.ChangeMode("-b *!*@" + whois.User.Hostname));
- Console.WriteLine(e.PrivateMessage.Message.Substring(7) + " " + "is unbanned");
- }
- else if (e.PrivateMessage.Message == "!leave")
- {
- channel.Part();
- Console.WriteLine("Bot left channel.");
- }
- else if (e.PrivateMessage.Message.StartsWith("!kick "))
- {
- var target = e.PrivateMessage.Message.Substring(7);
- channel.Kick(e.PrivateMessage.Message.Substring(6));
- Console.WriteLine(e.PrivateMessage.Message.Substring(6) + " " + "is kicked");
- }
- else if (e.PrivateMessage.Message == "!commands")
- {
- channel.SendMessage("--- commands list ---");
- channel.SendMessage("ban = !ban nick");
- channel.SendMessage("kick = !kick nick");
- channel.SendMessage("leave = !leave");
- channel.SendMessage("say = !say");
- channel.SendMessage("join = !join");
- Console.WriteLine("!commands requested");
- }
- else if (e.PrivateMessage.Message.StartsWith("!say "))
- {
- channel.SendMessage(e.PrivateMessage.Message.Substring(5));
- }
- else if (e.PrivateMessage.Message.StartsWith("!join "))
- {
- client.JoinChannel(e.PrivateMessage.Message.Substring(5));
- }
- else if (e.PrivateMessage.Message.StartsWith("!give "))
- {
- string fromvalue = System.IO.File.ReadAllText("/TimsBot/tokensystem/" + e.PrivateMessage.User.Nick);
- string tovalue = System.IO.File.ReadAllText("/TimsBot/tokensystem/" + e.PrivateMessage.User.Nick);
- }
- else if (e.PrivateMessage.Message.StartsWith("!tokens"))
- {
- string tokenvalue = System.IO.File.ReadAllText("/TimsBot/tokensystem/" + e.PrivateMessage.User.Nick);
- if (System.IO.File.Exists("/TimsBot/tokensystem/" + (e.PrivateMessage.Message.EndsWith())))
- {
- channel.SendMessage(e.PrivateMessage.User.Nick + " You have " + tokenvalue + " Tokens!");
- }
- else
- {
- System.IO.File.WriteAllText("/TimsBot/tokensystem/" + e.PrivateMessage.User.Nick, "10000");
- string tokenvalue2 = System.IO.File.ReadAllText("/TimsBot/tokensystem/" + e.PrivateMessage.User.Nick);
- channel.SendMessage(e.PrivateMessage.User.Nick + " You have " + tokenvalue2 + " Tokens!");
- }
- }
- else if (e.PrivateMessage.Message.StartsWith("!tokens_add"))
- {
- System.IO.File.AppendAllText("/TimsBot/tokensystem.txt", e.PrivateMessage.User.Nick + " " + (e.PrivateMessage.Message.Substring(12) + Environment.NewLine));
- }
- client.UserJoinedChannel += (f, g) =>
- {
- if (System.IO.File.Exists("/TimsBot/tokensystem/" + g.User.Nick))
- {
- }
- else {
- System.IO.File.WriteAllText("/TimsBot/tokensystem/" + g.User.Nick , "10000");
- }
- };
- };
- client.ConnectAsync();
- Application.Run();
- while (true) ;
- }
- }
- public static void HideConsoleWindow()
- {
- var handle = GetConsoleWindow();
- ShowWindow(handle, SW_HIDE);
- }
- [DllImport("kernel32.dll", SetLastError = true)]
- static extern bool AllocConsole();
- [DllImport("kernel32.dll")]
- static extern IntPtr GetConsoleWindow();
- [DllImport("user32.dll")]
- static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- const int SW_HIDE = 0;
- const int SW_SHOW = 5;
- public static void item1_Click(object sender, EventArgs e )
- {
- Environment.Exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement