Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2016-10-01 03:06:49, last edited by raprap (2019-03-26 03:32:15)

raprap
Member
Joined: 2015-02-20
Posts: 34

i need help programming my bot

using PlayerIOClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Dynamic.Runtime
using Yonom.EE;
using Yonom;
namespace CurseTagBot
{
    public partial class Mainform : Form
    {
    	public Mainform()
        {
            InitializeComponent();
            Password_TextBox.PasswordChar = Convert.ToChar("*");
            //Password_TextBox.Visible = false;
            if(!File.Exists(@"cyan.txt"))
            {
            	File.Create(@"cyan.txt");
            }
            if(!File.Exists(@"red.txt"))
            {
            	File.Create(@"red.txt");
            }
            if(!File.Exists(@"green.txt"))
            {
            	File.Create(@"green.txt");
            }
            if(!File.Exists(@"blue.txt"))
            {
            	File.Create(@"blue.txt");
            }
            if(!File.Exists(@"magenta.txt"))
            {
            	File.Create(@"magenta.txt");
            }
        }
        public Connection con;
        public Client client;
        public bool isConnected;
        public Dictionary<int, player> users = new Dictionary<int, player>();
        public userData userdata = new userData();
        public void saveJSON() 
        {
        	 File.WriteAllText("userData.json", JsonConvert.SerializeObject(userdata, Formatting.Indented));
        }
        public List<string> admins = new List<string>() {"raprap", "xaviourb007"};
        public List<string> userL = new List<string>();
        public List<string> hasEdit = new List<string>();
        public List<block> blockL = new List<block>();
        public List<string> yellow = new List<string>() {"bleen56", "raprap"};
        public List<string> cyan = new List<string>();
        public List<string> red = new List<string>();
        public List<string> blue = new List<string>();
        public List<string> magenta = new List<string>();
        public List<string> green = new List<string>();
		public int[,,] blocks = new int[2, 400, 650];
		public void ban(string username)
        {
        if (userdata.perms.ContainsKey(username)) 
          {
            userdata.perms[username] = "banned";
          }
        else 
          {
            userdata.perms.Add("username", "banned");
          }
          saveJSON();
        }
        public bool snake;
        public int snakeid;
        public int delay;
        public class block
        {
        	public int layer { get; set; }
			public int x { get; set; }
			public int y { get; set; }
			public int bid { get; set; }
			public object[] args { get; set; }
		}
        public class worldData 
        {
	        public Dictionary<string,string> teams { get; set; }
	        public Dictionary<string,string> perms { get; set; }
	        public Dictionary<string,user> users { get; set; }
        }
        public class user 
        {
	        public string username { get; set; }
	        public int userid { get; set; }
        }
        public class player
        {
            public string username{ get; set; }
            public int userid{ get; set; }
        }
        public void say(string msg)
        {
            con.Send("[CurseBot]: " + msg);
        }
        public void pm(string player, string msg)
        {
            con.Send("/pm " + player + " [CurseBot]: " + msg);
        }
        public void com(string msg)
        {
            con.Send("/" + msg);
        }
        public void loadTeam(string color)
        {
        	using(StreamReader sr = new StreamReader(@"" + color + ".txt"))
        	{
        		string line;
        		while ((line = sr.ReadLine()) != null)
			    {
        			switch(color.ToLower())
        			{
        				case "cyan":
        					{
        						cyan.Add(line);
        					}
        					break;
        				case "red":
        					{
        						red.Add(line);
        					}
        					break;
        				case "green":
        					{
        						green.Add(line);
        					}
        					break;
        				case "blue":
        					{
        						blue.Add(line);
        					}
        					break;
        				case "magenta":
        					{
        						magenta.Add(line);
        					}
        					break;
        			}
        		}
        	}
        }
        public void addTeamPlayer(string name, string color)
        {
        	switch(color.ToLower())
        	{
        		case "cyan":
        			{
        				if(!cyan.Contains(name))
        				{
        					cyan.Add(name);
        					using(StreamWriter sw = new StreamWriter(@"" + color + ".txt",true))
	        				{
	        					sw.Write(name);
	        				}
        				}
        			}
        			break;
        		case "red":
        			{
        				if(!red.Contains(name))
        				{
        					red.Add(name);
        					using(StreamWriter sw = new StreamWriter(@"" + color + ".txt",true))
	        				{
	        					sw.Write(name);
	        				}
        				}
        			}
        			break;
        		case "blue":
        			{
        				if(!blue.Contains(name))
        				{
        					blue.Add(name);
        					using(StreamWriter sw = new StreamWriter(@"" + color + ".txt",true))
	        				{
	        					sw.Write(name);
	        				}
        				}
        			}
        			break;
        		case "green":
        			{
        				if(!green.Contains(name))
        				{
        					green.Add(name);
        					using(StreamWriter sw = new StreamWriter(@"" + color + ".txt",true))
	        				{
	        					sw.Write(name);
	        				}
        				}
        			}
        			break;
        		case "magenta":
        			{
        				if(!magenta.Contains(name))
        				{
        					magenta.Add(name);
        					using(StreamWriter sw = new StreamWriter(@"" + color + ".txt",true))
	        				{
	        					sw.Write(name);
	        				}
        				}
        			}
        			break;
        			{
        	}
        }
        }
        public void replace(int replace, int replacer)
		{
			// I felt like adding a replace command
			List<block> temp = new List<block>();
			temp.AddRange(blockL);
			foreach(block b in temp)
			{
				if(b.bid == replace)
				{
					con.Send("b", b.layer, b.x, b.y, replacer);
					if(replacer == 0)
					{
						blockL.Remove(b);
					}
					else
					{
						blockL.Remove(b);
						blockL.Add(new block() {x = b.x, y = b.y, layer = b.layer, bid = replacer});
						blocks[b.layer, b.x, b.y] = replacer;
					}
				}
			}
		}
        public void LoadAdmins()
		{
			// bucz loading using init is boring
			using(StreamReader sr = new StreamReader(@"admins.txt"))
			{
				string line;
				while ((line = sr.ReadLine()) != null)
				{
					admins.Add(line);
				}
			}
		}
		public void RemoveAdmin(string player)
		{
			using(StreamReader sr = new StreamReader(@"admins.txt"))
			{
				using(StreamWriter sw = new StreamWriter(@"admins.txt"))
				{
					string line;
					while((line = sr.ReadLine()) != null)
					{
						if(line == player)
						{
							sw.WriteLine(line);
						}
					}
				}
			}
		}
		public void AddAdmins(string player)
		{
			using(StreamWriter sw = new StreamWriter(@"admins.txt", true))
			{
				sw.WriteLine(player);
			}
		}
        public void Connect_ButtonClick(object sender, EventArgs e)
        {
            if(!isConnected)
            {
                try
                 {
                	client = PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", Email_TextBox.Text, Password_TextBox.Text, null);
                	//client = PlayerIO.QuickConnect.FacebookOAuthConnect("everybody-edits-su9rn58o40itdbnw69plyw", Email_TextBox.Text, Password_TextBox.Text, null);
                	// FB ACCESS TOKEN: http://webcache.googleusercontent.com/search?q=cache:http://trustno1.info/capasha/fb_kg_ag.html
                	/*if (client == null)
						return;*/
                	
                	//Why put "public"? This is the mistake xaviourb007 made with sweetie bot, which is why it's giving me an error.
                	//Instead, there is some code I can provide which is on my EE Bot Turtorial guide.
                	//Would you like me to use it? [Y/N] > Y
                	//Ok. I'll provide a link to it, and first put in the new and fixed code for creating a join room
                	//Here is the link incase you want it> http://forums.everybodyedits.com/viewtopic.php?id=36087
                    string WorldID = worldID_TextBox.Text;
					con = client.Multiplayer.CreateJoinRoom((WorldID.ToLower().StartsWith("ow") ? WorldID.Replace("-", "") : WorldID),
                                                            (WorldID.ToLower().StartsWith("bw") ? "Beta" : "Everybodyedits" ) + client.BigDB.Load("config", "config")["version"],
                                                            true, null, null);
                    con.OnMessage += new MessageReceivedEventHandler(handlemsg);
                    con.Send("init");                 
                    isConnected = true;
                    connect_Button.Text = "Disconnect";
                 }
                    catch (PlayerIOError oops)
                 {
                    MessageBox.Show(Convert.ToString(oops), "PlayerIO Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                    catch (Exception oops2)
                 {
                    MessageBox.Show(Convert.ToString(oops2), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
            }
            else
            {
                say("Goodbye!");
                connect_Button.Text = "Connect";
                isConnected = false;
                con.Disconnect();
            }
        }
        public void handlemsg(object sender, PlayerIOClient.Message m)
        {
            switch (m.Type)
            {
                case "init":
                    {
            			LoadAdmins();
            			var chunks = InitParse.Parse(m);
            			foreach(DataChunk chunk in chunks)
            			{
            				foreach(Point pos in chunk.Locations)
            				{
            					if((int) chunk.Type != 0)
								{
								blocks[chunk.Layer, pos.X, pos.Y] = (int) chunk.Type;
								blockL.Add(new block() {
								           	x = pos.X,
								           	y = pos.Y,
								           	layer = chunk.Layer,
								           	bid = (int) chunk.Type
								           });
								}
            				}
            			}
            			loadTeam("cyan");
            			Thread.Sleep(750);
            			loadTeam("red");
            			Thread.Sleep(750);
            			loadTeam("blue");
            			Thread.Sleep(750);
            			loadTeam("mageta");
            			Thread.Sleep(750);
            			loadTeam("green");
            			Thread.Sleep(750);
                        say("Connected!");
                        con.Send("init2");
                    }
                    break;
                case "add":
                    {
                        string player = m.GetString(1);
                        say(player + " joined the world");
                        users.Add(m.GetInt(0), new player() {username = m.GetString(1), userid = m.GetInt(0)});
                        if(admins.Contains(player))
                        {
                            con.Send("/giveedit " + player);
                        }
                        if(ban.Contains(player))
                        {
                            con.Send("/kick " + player + " You are banned from this world!");
                        }
                        if(m.GetBoolean(23) == true)
						{
							hasEdit.Add(player);
						}
                        if(cyan.Contains(player))
                        {
                        	com("tp " + player + " 4 15");
                        }
                        if(red.Contains(player))
                        {
                        	com("tp " + player + " 4 11");
                        }
                        if(blue.Contains(player))
                        {
                        	com("tp " + player + " 6 11");
                        }
                        if(magenta.Contains(player))
                        {
                        	com("tp " + player + " 6 15");
                        }
                        if(green.Contains(player))
                        {
                        	com("tp " + player + " 8 11");
                        }
                        if(red.Contains(player))
                        {
                        	com("tp " + player + " 4 11");
                        }
                        var username = m.GetString(1);
                        if (userdata.perms.ContainsKey(username)) 
                          {
                          if (userdata.perms[username] == "banned") 
                            {
                              connection.Send("say", "/kick {username} You are banned");
                            }
                          }
                    }
                    break;
                case "left":
                    {
                        string player = users[m.GetInt(0)].username; // This is how you're going to detect username/player from now on.
                        say(player + " left");
                        if(users.ContainsKey(m.GetInt(0)))
                        {
                            users.Remove(m.GetInt(0));
                        }
                        if(hasEdit.Contains(player))
						{
							hasEdit.Remove(player);
							//
						}
                    }
                    break;
                case "editRights":
					{
						string player = users[m.GetInt(0)].username;
						if(m.GetBoolean(1) == true)
						{
							hasEdit.Add(player);
							//
						}
						if(m.GetBoolean(1) == false)
						{
							hasEdit.Remove(player);
							//
						}
					}
					break;
                case "say":
                    { 
                        string player = users[m.GetInt(0)].username;
                        if (Regex.IsMatch(m.GetString(1).Substring(0, 1), @"\.|\!"))
                        {
                            var cmdprefix = m.GetString(1).Substring(0, 1);
                            var cmds = m.GetString(1).ToLower().Split(' ');
                            var rest2 = m.GetString(1).Remove(0, 5); 
                            if(cmds[0].StartsWith(cmdprefix + "help"))
                            {
                                pm(player,  "!amiadmin , !adminhelp , !creator, !download , !teams");
                            }
                            if(cmds[0].StartsWith(cmdprefix + "creator"))
                            {
                            	pm(player, "Bot Made By: Raprap");
                            	pm(player, "Xaviourb007 the potato was here");
                            }
                            if(cmds[0].StartsWith(cmdprefix + "amiadmin"))
                           
                            {
                                if(admins.Contains(player))
                                {
                                    pm(player, "You're an admin!");
                                }
                                else
                                {
                                    pm(player, "You're not an admin!");
                                }
                            }
                            if(cmds[0].StartsWith(cmdprefix + "adminhelp"))
                            {
                                if(admins.Contains(player))
                                {
                                    pm(player, "!kick, !gedit, !redit, !save, !clear, !load, !ban, !admin, !replace, !start, !stop");
                                }
                                else
                                {
                                    pm(player, "You're not an admin!");
                                }
                            }
                            if(cmds[0].Equals(cmdprefix + "team"))
                            {
                            	if(cmds.Length == 2)
                            	{
                            		if(!cyan.Contains(player) && !red.Contains(player) && !blue.Contains(player) && !yellow.Contains(player) && !magenta.Contains(player) && !green.Contains(player))
                            		{
	                            		if(cmds[1].ToLower() == "cyan") // <=
	                            		{
	                            			com("tp " + player + " 4 15");
	                            			pm(player, "You're now an Aqua Agents member!");
	                            			addTeamPlayer(player, "cyan");
	                            		}
	                                    if(cmds[1].ToLower() == "red") // <=
	                            		{
	                            			com("tp " + player + " 4 11");
	                            			pm(player, "You're now an Red Rangers member!");
	                            			addTeamPlayer(player, "red");
	                            		}
	                                    if(cmds[1].ToLower() == "blue") // <=
	                            		{
	                            			com("tp " + player + " 6 11");
	                            			pm(player, "You're now an Blue Squad member!");
	                            			addTeamPlayer(player, "blue");
	                            		}
	                                    if(cmds[1].ToLower() == "magenta") // <=
	                            		{
	                            			com("tp " + player + " 6 15");
	                            			pm(player, "You're now an Magenta Mage member!");
	                            			addTeamPlayer(player, "magenta");
	                            		}
	                                    if(cmds[1].ToLower() == "green") // <=
	                            		{
	                            			com("tp " + player + " 8 11");
	                            			pm(player, "You're now an Green Soldier member!");
	                            			addTeamPlayer(player, "green");
	                            		}
                            		}
                            		else
                            		{
                            			pm(player, "You're already in a team!");
                            		}
                            		// more if statements
                            	}
                            }
                            if(admins.Contains(player))
                            {
                                if(cmds[0].StartsWith(cmdprefix + "kick"))
                                {
                                    if(cmds.Length == 2)
                                    {
                                        if(!admins.Contains(cmds[1]))
                                        {
                                            com("kick " + cmds[1]);
                                            say(player + " kicked " + cmds[1] + " from this world!");
                                        }
                                    }
                                }
                                if(cmds[0].StartsWith(cmdprefix + "ban"))
                                {
                                    if(cmds.Length == 2)
                                    {
                                        if(!admins.Contains(cmds[1]))
                                        {
                                            com("kick " + cmds[1]);
                                            say(player + " banned " + cmds[1] + " from this world!");
                                            ban.Add(cmds[1]);
                                        }
                                    }
                                }
                                if(cmds[0].StartsWith(cmdprefix + "load"))
                                {
                                    com("loadlevel");
                                }
                                if(cmds[0].StartsWith(cmdprefix + "say"))
                                {
                                	say(rest2);
                                }
                                if(cmds[0].StartsWith(cmdprefix + "clear"))
                                {
                                    com("clear");
                                }
                                if(cmds[0].StartsWith(cmdprefix + "save"))
                                {
                                    con.Send("save");
                                    say(cmds[1] + " Saved!");
                                }
                                if(cmds[0].Equals(cmdprefix + "edit"))
                                {
                                	if(cmds.Length == 2)
                                	{
                                		if(cmds[1] != "raprap")
                                		{
                                			if(!hasEdit.Contains(cmds[1]))
                                			{
                                				com("giveedit " + cmds[1]);
                                				pm(cmds[1], player + " gave you edit! Hooray!");
                                				pm(player, "Gave edit to " + cmds[1]);
                                			}
                                			else
                                			{
                                				com("removeedit " + cmds[1]);
                                				pm(cmds[1], player + " took away your edit! Aww");
                                				pm(player, "Took away edit from " + cmds[1]);
                                			}
                                		}
                                		else
                                		{
                                			pm(player, "Silly admin, you cannot take the owner's edit!");
                                		}
                                	}
                                	else
                                	{
                                		pm(player, "Whoops! Incorrect Command Usage. !edit <player>");
                                	}
                                }
                            }
                           if (player == "raprap" | player == "xaviourb007")
                           {
                                if(cmds[0].StartsWith(cmdprefix + "admin"))
                            	{
                            		if(cmds.Length == 2)
                            		{
                            			if(!admins.Contains(cmds[1]))
                            			{
                            				AddAdmins(cmds[1]);
                            				say(cmds[1] + " is now an admin!");
                            			}
                            	        else
                            			{
                            		        RemoveAdmin(cmds[1]);
                            			    say(cmds[1] + " isn't an admin anymore!");
                            			}
                            		}
                            	}
                                if(cmds[0].StartsWith(cmdprefix + "replace"))
                                {
                                	if(cmds.Length == 3)
                                	{
                                		replace(int.Parse(cmds[1]), int.Parse(cmds[2]));
                                		say("Done");
                                	}
                                }
                                if(cmds[0].StartsWith(cmdprefix + "snake"))
                                {
                                	if(cmds.Length == 1)
                                	{
                                		if(!snake)
                                		{
                                			snake = true;
                                			pm(player, "Snake is enabled!");
                                		}
                                		else
                                		{
                                			snake = false;
                                			pm(player, "Snake is disabled!");
                                		}
                                	}
                                	else if(cmds.Length == 3)
                                	{
                                		if(cmds[1] == "block")
                                		{
                                			if(Regex.IsMatch(cmds[2], @"^\d+$"))
                                			{
                                				snakeid = int.Parse(cmds[2]);
                                				pm(player, "Use block id " + cmds[2] + " for snake!");
                                			}
                                		}
                                		else if(cmds[1] == "delay")
                                		{
                                			if(Regex.IsMatch(cmds[2], @"^\d+$"))
                                			{
                                				delay = int.Parse(cmds[2]);
                                				pm(player, "Delay set to " + cmds[2] +"!");
                                			}
                                		}
                                	}
                                	else if(cmds.Length == 2)
                                	{
                                		if(cmds[1] == "block")
                                		{
                                			pm(player, "The block that is used for snake is " + snakeid);
                                		}
                                		else if(cmds[1] == "delay")
                                		{
                                			pm(player, "The delay is " + cmds[2] + " miliseconds");
                                		}
                                	}
                                	else
                                	{
                                		pm(player, "Whoops! Incorrect Command Usage. !snake | !snake block <id> | !snake block | !snake delay <miliseconds> | !snake delay");
                                	}
                                }
                            }
                        }}
                        break;
                   case "write":
                     {
                     	string title = m.GetString(0);
						string msg = m.GetString(1);
						string player = title.Split(' ')[1];
						if(title.Contains("> you") && (player == "raprap" || player == "xaviourb007"))
						{
							if(Regex.IsMatch(msg.Substring(0, 1), @"\!|\.|\~|\$|\:"))
							{
								var prefix = msg.Substring(0, 1).ToLower();
								var cmd = msg.ToLower().Split(' ');
								if(cmd[0].Equals(prefix + "help"))
								{
									pm(player, "DEBUG: blocks, repeat");
								}
								if(cmd[0].Equals(prefix + "blocks"))
								{
									pm(player, blockL.Count().ToString());
								}
								if(cmd[0].Equals(prefix + "repeat"))
								{
									string rest = m.GetString(1).Remove(0, 8);
									say(rest);
								}
							}
						}
                     }
                        break;
                   case "info":
                     {
                     	string title = m.GetString(0);
                     	string text = m.GetString(1);
                     	MessageBox.Show(text, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                     break;
                    case "reset":
                     {
                     	blockL.Clear();
                     	var chunks = InitParse.Parse(m);
            			foreach(DataChunk chunk in chunks)
            			{
            				foreach(Point pos in chunk.Locations)
            				{
            					if((int) chunk.Type != 0)
								{
								blocks[chunk.Layer, pos.X, pos.Y] = (int) chunk.Type;
								blockL.Add(new block() {
								           	x = pos.X,
								           	y = pos.Y,
								           	layer = chunk.Layer,
								           	bid = (int) chunk.Type
								           });
								}
            				}
            			}
                     }
                     break;
                    case "clear":
                     {
                     	blockL.Clear();
                     }
                     break;
                    case "team":
                     {
                     	string player = users[m.GetInt(0)].username;
                     	int id = m.GetInt(1);
                     	if(id != 4 && cyan.Contains(player))
                     	{
                     		com("setteam " + player + " cyan");
                     	}
                     	if(id != 1 && red.Contains(player))
                     	{
                     		com("setteam " + player + " red");
                     	}
                     	if(id != 2 && blue.Contains(player))
                     	{
                     		com("setteam " + player + " blue");
                     	}
                     	if(id != 3 && green.Contains(player))
                     	{
                     		com("setteam " + player + " green");
                     	}
                     	if(id != 5 && magenta.Contains(player))
                     	{
                     		com("setteam " + player + " magenta");
                     	}
                     	if(id != 6 && yellow.Contains(player))
                     	{
                     		com("setteam " + player + " yellow");
                     	}
                     	// Teams id is in the protocol
                     }
                     break;
                     #region block placement
				case "b":
					{
						string player = users[m.GetInt(4U)].username;
						int int1 = m.GetInt(0U); // Layer
						int int2 = m.GetInt(3U); // BlockID
						int int3 = m.GetInt(1U); // X
						int int4 = m.GetInt(2U); // Y
						blocks[int1, int3, int4] = int2;
						if(int2 == 0)
						{
							List<block> temp = new List<block>();
							temp.AddRange(blockL);
							foreach(block b in temp)
							{
								if(b.x == int3 && b.y == int4)
								{
									blockL.Remove(b);
									break;
								}
							}
						}
						else if(snake == true && snakeid == int2)
						{
							con.Send("b", int1, int3, int4, 0);
							Thread.Sleep(delay);
						}
						else
						{
							blockL.Add(new block() {x = int3, y = int4, bid = int2, layer = int1});
						}
					}
					break;
				case "bc":
					{
						int @int = m.GetInt(2U);
						blocks[0, m.GetInt(0U), m.GetInt(1U)] = @int;
					}
					break;
				case "br":
					{
						int @int = m.GetInt(2U);
						blocks[0, m.GetInt(0U), m.GetInt(1U)] = @int;
					}
					break;
				case "bs":
					{
						int @int = m.GetInt(2U);
						blocks[0, m.GetInt(0U), m.GetInt(1U)] = @int;
					}
					break;
				case "pt":
					{
						int @int = m.GetInt(2U);
						blocks[0, m.GetInt(0U), m.GetInt(1U)] = @int;
					}
					break;
				case "ts":
					{
						int @int = m.GetInt(2U);
						blocks[0, m.GetInt(0U), m.GetInt(1U)] = @int;
					}
					break;
					#endregion
               }
         }
     }
    }

Offline

#2 2016-10-01 03:09:47, last edited by Vinyl Melody (2016-10-01 03:10:02)

Vinyl Melody
Formerly BananaMilkShake
Joined: 2016-06-19
Posts: 616

Re: i need help programming my bot

1.)

 [code] and [/code] exists. 

2.) There's Thread.Sleep(750); I think you're just lazy and didn't wait. Try removing them if it works.
3.) Welcome to the forums nub
tnx hummerz5


cb0de83627.png
Thanks to: Ernesdo (Current Avatar), Zoey2070 (Signature)

Very inactive, maybe in the future, idk.

Offline

#3 2016-10-01 05:40:44, last edited by capasha (2016-10-01 05:55:08)

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: i need help programming my bot

Make a pastebin instead. And btw, when you write to a file without "true" it will just add that word and the other words will be removed.

Wrong:

using(StreamWriter sw = new StreamWriter(@"" + color + ".txt"))
	        				{
	        					sw.Write(name);
	        				}

Correct:

using(StreamWriter sw = new StreamWriter(@"" + color + ".txt",true))
	        				{
	        					sw.Write(name);
	        				}

Use something like: http://pastebin.com/dT3RcVAC, to login to multiple sites.


Why do you use delay?
You should loadteam when you open the program. And not when init is executed.

            			loadTeam("cyan");
            			Thread.Sleep(750);
            			loadTeam("red");
            			Thread.Sleep(750);
            			loadTeam("blue");
            			Thread.Sleep(750);
            			loadTeam("mageta");
            			Thread.Sleep(750);
            			loadTeam("green");
            			Thread.Sleep(750);

regular expression part looks like it is from my old bot //forums.everybodyedits.com/img/smilies/tongue
It used cmdprefix too.

Offline

#4 2016-10-01 15:57:13, last edited by Koya (2016-10-02 00:20:51)

Koya
Fabulous Member
From: The island with those Brits
Joined: 2015-02-18
Posts: 6,310

Re: i need help programming my bot

All of those Lists can be condensed into 3 Dictionaries; it'll be easier to manage.

JSON

{
	"teams": {
		"bleen56":"yellow", 
		"raprap":"yellow"
	},
	"perms":{
		"raprap": "admin",
		"xaviourb007:"admin"
	,
	"users":{
		"-1":{
			"username": "_username",
			"userid": -1
		}
	}
}

Suggested perms: banned, user, edit, god, godedit, mod, admin

C# - class structure

class worldData {
	public Dictionary<string,string> teams { get; set; }
	public Dictionary<string,string> perms { get; set; }
	public Dictionary<string,user> users { get; set; }
}
class user {
	public string username { get; set; }
	public int userid { get; set; }
	public user(string username, int userid) {
		this.username = username;
		this.userid = userid;
	}
}

To use this:
• First you need to get Newtonsoft.JSON, open the NuGet packet manager and it's #1 without having to search for it.
• You need to declare a new userData, at the same place that you have your lists - replace them with

C#

public userData userdata = new userData();

When the app starts run:

C#

userdata = JsonConvert.DeserializeObject<userData>(File.ReadAllText("userData.json"));

• So now if you do userdata.teams["raprap"] you will get "yellow" in return; you will need to check to see if the dictionary contains the key "raprap" first (or catch errors).

Example: banning user and checking if user is banned.

C#

public void ban(string username)
{
   if (userdata.perms.ContainsKey(username)) 
   {
      userdata.perms[username] = "banned";
   }
   else 
   {
      userdata.perms.Add("username", "banned");
   }
   saveJSON();
}
C#

public void saveJSON() {
   File.WriteAllText("userData.json", JsonConvert.SerializeObject(userdata, Formatting.Indented));
}
C#

case "add":
   var username = m.GetString(1);
   if (userdata.perms.ContainsKey(username)) 
   {
      if (userdata.perms[username] == "banned") 
      {
         connection.Send("say", $"/kick {username} You are banned");
      }
   }
   break;

The process is the same for getting and setting all the other data.


Po9cnQh.png

PLNQVL8.png
Thank you eleizibeth ^

1SYOldu.png

I stack my signatures rather than delete them so I don't lose them
giphy.gif

WfSi4mm.png

Offline

Wooted by: (2)

#5 2016-10-02 00:08:31

Vinyl Melody
Formerly BananaMilkShake
Joined: 2016-06-19
Posts: 616

Re: i need help programming my bot

Wow, koya. Raprap's just a beginner.


cb0de83627.png
Thanks to: Ernesdo (Current Avatar), Zoey2070 (Signature)

Very inactive, maybe in the future, idk.

Offline

#6 2016-10-02 00:10:26, last edited by Koya (2016-10-02 00:22:00)

Koya
Fabulous Member
From: The island with those Brits
Joined: 2015-02-18
Posts: 6,310

Re: i need help programming my bot

BananaMilkShake wrote:

Wow, koya. Raprap's just a beginner.

They're already trying to load data from file - may as well do it the right way.

I should convert the pseudocode to C# though


Edit: if he gives me a wall of text then I'm just working on what was shown to me - I could remove a load of those lines turning a wall into an easily manageable piece of code.


Po9cnQh.png

PLNQVL8.png
Thank you eleizibeth ^

1SYOldu.png

I stack my signatures rather than delete them so I don't lose them
giphy.gif

WfSi4mm.png

Offline

#7 2016-10-02 02:57:04

John
Member
Joined: 2019-01-11
Posts: 1,974

Re: i need help programming my bot

+1 for suggesting the use of JSON!

JSON MASTER STORAGE METHOD


PW?scale=2

Offline

Wooted by: (2)

#8 2016-10-02 12:01:25

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: i need help programming my bot

Emalton wrote:

+1 for suggesting the use of JSON!

JSON MASTER STORAGE METHOD

Serialized binary would be better if it were a public bot (otherwise people could (more) easily edit the values).

Offline

#9 2016-10-02 12:04:51

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: i need help programming my bot

den3107 wrote:
Emalton wrote:

+1 for suggesting the use of JSON!

JSON MASTER STORAGE METHOD

Serialized binary would be better if it were a public bot (otherwise people could (more) easily edit the values).

This is a terrible idea. The whole point of storing files in json is to have them be in a human readable format, for a good reason. We should have the right to know what data programs store on our computers don't we?
Sign the files if you want to prevent tampering with the data but don't use custom formats to gain the appearance of security.


I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.

Offline

Wooted by: (2)

#10 2016-10-02 14:32:43

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: i need help programming my bot

Not that I disagree with you, but you just said 'hey you shouldn't do this because it obscures data' and then said 'hey here's how you should obscure data' I think you potentially missed how one obscuring method is better than the other?

Offline

#11 2016-10-03 09:37:03

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: i need help programming my bot

hummerz5 wrote:

Not that I disagree with you, but you just said 'hey you shouldn't do this because it obscures data' and then said 'hey here's how you should obscure data' I think you potentially missed how one obscuring method is better than the other?

I think signing is a method to prevent people from changing the file (or perhaps a check if it has been changed) and not a way to obscure the data.

Offline

Wooted by:

#12 2016-10-03 10:17:07

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,830

Re: i need help programming my bot

Koya, there's no "right way" to save and load data from file, so don't push JSON at people. It's more complicated than necessary, especially for a beginner.

A newbie should start with the File class and local txts.


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

Wooted by: (2)

#13 2016-10-06 07:14:12, last edited by Vinyl Melody (2016-10-14 07:26:53)

Vinyl Melody
Formerly BananaMilkShake
Joined: 2016-06-19
Posts: 616

Re: i need help programming my bot

I actually liked koya's C# part.
Would you mind expanding it and making it more friendly?


I dont wanna spoil it but I actually made the bot for raprap, I made the 90% (base) and he just did the rest.
Fun fact: Raprap doesn't know C#.

//Why put "public"? This is the mistake xaviourb007 made with sweetie bot, which is why it's giving me an error.

Yes I know im an idiot.


cb0de83627.png
Thanks to: Ernesdo (Current Avatar), Zoey2070 (Signature)

Very inactive, maybe in the future, idk.

Offline

Vinyl Melody1475734452628237

Board footer

Powered by FluxBB

[ Started around 1713630567.2951 - Generated in 0.262 seconds, 10 queries executed - Memory usage: 1.7 MiB (Peak: 1.96 MiB) ]