Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Discord;
- using Discord.Audio;
- using Discord.Commands;
- using Discord.Commands.Permissions.Levels;
- using Discord.Modules;
- using System;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using DiscordBot.Commands;
- namespace DiscordBot
- {
- public class Program
- {
- static string email = "";
- static string password = "";
- public static string path = System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("DiscordBot.exe", "");
- public static string gameState = "idle";
- static void Main(string[] args)
- {
- string lastuser = "";
- DebugMessage("Please input login email.");
- Console.Write(" >");
- email = Console.ReadLine();
- DebugMessage("Please input login password.");
- Console.Write(" >");
- password = Console.ReadLine();
- //ConsoleKey keyPressed = Console.ReadKey(true).Key;
- //while(keyPressed != ConsoleKey.Enter)
- //{
- // if (keyPressed != ConsoleKey.Backspace)
- // {
- // Console.Write('*');
- // password += keyPressed;
- // }
- // else
- // {
- // Console.Write("\b");
- // password += "\b";
- // }
- // keyPressed = Console.ReadKey(true).Key;
- //}
- var client = new DiscordClient();
- var ponertimer = new System.Threading.Timer((e) =>
- {
- PonerLand.Tick(client);
- }, null, 0, (int)TimeSpan.FromMinutes(8).TotalMilliseconds);
- var questiontimer = new System.Threading.Timer((e) =>
- {
- lastuser = "";
- }, null, 0, (int)TimeSpan.FromMinutes(60).TotalMilliseconds);
- //Display all log messages in the console
- client.Log.Message += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");
- client.MessageReceived += (s, e) =>
- {
- //Log messages
- DebugMessage("Log", string.Format("[{0}] {1}: {2}", e.Message.Timestamp, e.Message.User, e.Message.Text), ConsoleColor.DarkGray);
- LogCommand.AddLine(e.Message);
- if (!e.Message.IsAuthor)
- {
- //Things that can't be responded to chooser.
- if(e.Message.User.ToString() != "Choosie#9470")
- {
- /**if (e.Message.Text.ToLower().Contains("wew"))
- {
- e.Channel.SendMessage("lad");
- DebugMessage("A wew has been ladded.");
- }
- if (e.Message.Text.ToLower().Contains("lad"))
- {
- e.Channel.SendMessage("wew");
- DebugMessage("A lad has been wewed.");
- }*/
- }
- if (e.Message.Text.ToLower().EndsWith("?") && e.Message.User.Name == lastuser && !e.Message.Text.ToLower().Contains("choosie"))
- {
- e.Channel.SendMessage(RandomCommand.Fortune());
- bool temp = false;
- questiontimer = new System.Threading.Timer((f) =>
- {
- if (temp)
- {
- lastuser = "";
- }
- else
- {
- temp = true;
- }
- }, null, 0, (int)TimeSpan.FromMinutes(.5).TotalMilliseconds);
- }
- else {
- if (e.Message.Text.ToLower().StartsWith("dicey,"))
- {
- DebugMessage(lastuser);
- lastuser = e.Message.User.Name;
- DebugMessage(lastuser);
- e.Channel.SendMessage(RandomCommand.Fortune());
- bool temp = false;
- questiontimer = new System.Threading.Timer((f) =>
- {
- if (temp)
- {
- lastuser = "";
- }
- else
- {
- temp = true;
- }
- }, null, 0, (int)TimeSpan.FromMinutes(.5).TotalMilliseconds);
- }
- }
- //Commands
- if (e.Message.Text.StartsWith("?"))
- {
- DebugMessage(string.Format("[{0}] has just called {1}", e.Message.User, e.Message.Text));
- string[] command = e.Message.Text.Replace("?", "").Split();
- if (gameState == "idle")
- {
- switch (command[0])
- {
- //case "wake":
- // if (command.Length > 1)
- // {
- // if (command[1] != "")
- // {
- // e.Channel.SendMessage(string.Format("Hey @{0}, get up!", command[1]));
- // }
- // else
- // {
- // e.Channel.SendMessage("I'm already up, dumbass.");
- // }
- // }
- // break;
- case "exit":
- if (e.Message.User.Id == 135822482895536128)
- {
- Environment.Exit(0);
- }
- break;
- case "fortune":
- e.Channel.SendMessage(RandomCommand.Fortune());
- break;
- case "roll":
- if (command.Length > 1 && command[1].Contains("d"))
- {
- Random r = new Random();
- string die = command[1];
- int mod = 0;
- if (command[1].Contains("+"))
- {
- die = command[1].Split('+')[0];
- int.TryParse(command[1].Split('+')[1], out mod);
- }
- //bool negative = false;
- if (command[1].StartsWith("-"))
- {
- //negative = true;
- command[1] = command[1].Substring(1);
- }
- if (command[1].Contains("-"))
- {
- die = command[1].Split('-')[0];
- int.TryParse(command[1].Split('-')[1], out mod);
- mod = -mod;
- }
- int count;
- int.TryParse(die.Split('d')[0], out count);
- int sides;
- int.TryParse(die.Split('d')[1], out sides);
- if (count <= 9999999 && sides <= 9999999)
- {
- int[] results = new int[Math.Abs(count)];
- int sum = 0;
- if (count > 0)
- {
- for (int i = 0; i < count; i++)
- {
- results[i] = r.Next(sides) + 1;
- sum += results[i];
- }
- }
- else
- {
- for (int i = 0; i > count; i--)
- {
- results[Math.Abs(i)] = -r.Next(sides) - 1;
- sum += results[Math.Abs(i)];
- }
- }
- sum += mod;
- if (count > 100 || sides > 1000)
- {
- e.Channel.SendMessage(string.Format("{0} = [Compressed due to size]", sum));
- }
- else
- {
- e.Channel.SendMessage(string.Format("{2} = [{0} + {1}]", string.Join(" + ", results), mod, sum));
- }
- }
- }
- break;
- //case "kill":
- // if (command.Length > 1)
- // {
- // if (command[1] != "")
- // {
- // if (command[1].ToLower() == "dicey")
- // {
- // e.Channel.SendMessage("You fucker.");
- // }
- // if (e.Message.User.Id == 135822482895536128)
- // {
- // PonerLand.Kill(command[1].ToLower());
- // e.Channel.SendMessage(command[1].Replace('_', ' ') + " is dead.");
- // }
- // else
- // {
- // e.Channel.SendMessage("You are not allowed to kill poners.");
- // }
- // }
- // }
- // else
- // {
- // e.Channel.SendMessage(RandomCommand.Random(new string[] { "Nah.", "Not right now", "Maybe later.", "Okay. Your waifu is dead.", "You sure you want me to?", "I'm not Bath."}));
- // }
- // break;
- case "bully":
- case "billy":
- if (command.Length > 1)
- {
- if (command[1] != "")
- {
- if (command[1].ToLower() == "me")
- {
- if (e.Message.User.Nickname != "")
- {
- command[1] = e.Message.User.Nickname.ToLower();
- }
- else
- {
- command[1] = e.Message.User.Name.ToLower();
- }
- }
- if (command[1].ToLower() == "you")
- command[1] = "Dicey";
- e.Channel.SendMessage(BillyCommand.GetBilly(command[1]));
- }
- else
- {
- e.Channel.SendMessage("Fuck you, spacebar.");
- }
- }
- else
- {
- e.Channel.SendMessage("You all are disgraces that shouldn't feel happiness.");
- }
- break;
- case "random":
- if (command.Length > 1)
- {
- string[] tokens = new string[command.Length - 1];
- for (int i = 1; i < command.Length; i++)
- {
- tokens[i - 1] = command[i];
- }
- string joined = string.Join(" ", tokens);
- tokens = joined.Split(',');
- e.Channel.SendMessage("[`" + RandomCommand.Random(tokens).Trim() + "`]");
- }
- break;
- case "help":
- e.Channel.SendMessage("Generic Commands:\n\t?help, Displays Commands\n\t?random, Chooses a random string from a list given. Separated by commas" +
- "\n\t?bully or ?billy, Bullies the targetted person\nUtility Commands:\n\t?roll \"x\"d\"y\"+\"z\", where \"x\" is the amount of dice, \"y\" is the amount of sides, and \"z\" is the amount added or subtracted" +
- "\n\t?fortune, Gives an 8-ball like answer.\nPonyland Commands: (Ponyland is currently disabled, due to inactivity)\n\t?boop, boops the specified poner on the snootle\n\t?brushie, brushes the specified poner, cleaning them\n\t?feed, feeds the poner. They will only accept if they are hungry." +
- "\n\t?ded, displays the list of poners that you have killed out of neglect. You monster.\n\t?new, Creates a new poner with the specified name. You can not make duplicate poners, or ded poners.\n\t?ponies or ?poners, Displays a list of all currently alive poners.\n\tBattleship Commands:\n\t?battleship, Starts a game of battleship.");
- break;
- case "boop":
- case "newspaper":
- //if (command.Length > 1)
- //{
- // if(command[1] != "")
- // {
- // if(command[1].ToLower() == "dicey")
- // {
- // e.Channel.SendMessage("[scrunch]");
- // }
- // e.Channel.SendMessage(PonerLand.Boop(command[1].ToLower().Replace('_', ' '), e.Message.User.Nickname));
- // }
- //}
- //else
- //{
- e.Channel.SendMessage("[scrunch]");
- //}
- break;
- case "hug":
- //if (command.Length > 1)
- //{
- // if (command[1] != "")
- // {
- // if (command[1].ToLower() == "dicey")
- // {
- // e.Channel.SendMessage("I can't hug myself, stupid.");
- // }
- // else {
- // e.Channel.SendMessage(PonerLand.Hug(command[1].ToLower().Replace('_', ' '), e.Message.User.Nickname));
- // }
- // }
- //}
- //else
- //{
- e.Channel.SendMessage("[hug]");
- //}
- break;
- case "brushie":
- //if (command.Length > 1)
- //{
- // if (command[1] != "")
- // {
- // if (command[1].ToLower() == "dicey")
- // {
- // e.Channel.SendMessage("[pleased dicey noises]");
- // }
- // e.Channel.SendMessage(PonerLand.Brushie(command[1].ToLower().Replace('_', ' '), e.Message.User.Nickname));
- // }
- //}
- //else
- //{
- e.Channel.SendMessage("[pleased dicey noises]");
- //}
- break;
- case "feed":
- //if (command.Length > 1)
- //{
- // if (command[1] != "")
- // {
- // if (command[1].ToLower() == "dicey")
- // {
- // e.Channel.SendMessage("");
- // }
- // e.Channel.SendMessage(PonerLand.Feed(command[1].ToLower().Replace('_', ' '), e.Message.User.Nickname));
- // }
- //}
- //else
- //{
- e.Channel.SendMessage("[pleased dicey noises]");
- //}
- break;
- //case "ponies":
- //case "poners":
- // e.Channel.SendMessage("```" + string.Join("\n", PonerLand.GetPoners()).Replace('_', ' ') + "```");
- // break;
- //case "new":
- // if (command.Length > 1)
- // {
- // PonerLand.NewPoner(command[1], e.Message);
- // }
- // break;
- //case "ded":
- //case "dead":
- // e.Channel.SendMessage("```" + string.Join(", ", PonerLand.GetDed()).Replace('_', ' ') + "```");
- // break;
- case "battleship":
- gameState = "battleship";
- Battleship.StartGame(e.Server);
- break;
- }
- }
- if (gameState == "battleship")
- {
- switch(command[0])
- {
- case "help":
- e.Channel.SendMessage("A game of battleship is currently in session. type ?quit to end the game prematurely. ?shoot (letter)(number) is the command to shoot. ?place (letter)(number) (facing (1 up, 2 right, 3 down, 4 left)) is the command to place at the beginning, with facing 1 being up, and going clockwise to 4.");
- break;
- case "quit":
- gameState = "idle";
- break;
- case "shoot":
- if (Battleship.gameState == "playing")
- {
- if (command[1] != null)
- {
- int row;
- bool correct = int.TryParse(command[1].Substring(1), out row);
- int column;
- switch (command[1].ToLower()[0])
- {
- case 'a':
- column = 0;
- break;
- case 'b':
- column = 1;
- break;
- case 'c':
- column = 2;
- break;
- case 'd':
- column = 3;
- break;
- case 'e':
- column = 4;
- break;
- case 'f':
- column = 5;
- break;
- case 'g':
- column = 6;
- break;
- case 'h':
- column = 7;
- break;
- case 'i':
- column = 8;
- break;
- case 'j':
- column = 9;
- break;
- default:
- column = 10;
- break;
- }
- if (correct && column < 10 && column >= 0)
- {
- Battleship.Turn(e.Server, row - 1, column);
- }
- else
- {
- e.Channel.SendMessage("That's not how you say it, dumbass. It's letter, then number. Like A1, or E10. No space inbetween.");
- }
- }
- else
- {
- e.Channel.SendMessage("Bang! Oh, you wanted to shoot somewhere specific. Why didn't you say so?");
- }
- }
- else
- {
- e.Channel.SendMessage("You can't shoot 'till the game's started, dummy.");
- }
- break;
- case "place":
- if (Battleship.gameState == "placing")
- {
- if (command[1] != null)
- {
- int row;
- bool correct = int.TryParse(command[1].Substring(1), out row);
- int column;
- switch (command[1].ToLower()[0])
- {
- case 'a':
- column = 0;
- break;
- case 'b':
- column = 1;
- break;
- case 'c':
- column = 2;
- break;
- case 'd':
- column = 3;
- break;
- case 'e':
- column = 4;
- break;
- case 'f':
- column = 5;
- break;
- case 'g':
- column = 6;
- break;
- case 'h':
- column = 7;
- break;
- case 'i':
- column = 8;
- break;
- case 'j':
- column = 9;
- break;
- default:
- column = 10;
- break;
- }
- int dir = 0;
- int.TryParse(command[2], out dir);
- if (correct && column < 10 && column >= 0 && dir != 0)
- {
- Battleship.PlacePlayerShip(e.Server, row - 1, column, dir);
- }
- else
- {
- e.Channel.SendMessage("Example, ?place A1 3, which would place a ship in the top left corner facing down.");
- }
- }
- else
- {
- e.Channel.SendMessage("Example, ?place A1 3, which would place a ship in the top left corner facing down.");
- }
- }
- else
- {
- e.Channel.SendMessage("You already placed them, though!");
- }
- break;
- }
- }
- }
- }
- };
- //Echo back any message received, provided it didn't come from the bot itself
- /**client.MessageReceived += async (s, e) =>
- {
- if (!e.Message.IsAuthor)
- {
- await e.Channel.SendMessage(e.Message.Text);
- }
- };*/
- //Convert our sync method to an async one and block the Main function until the bot disconnects
- client.ExecuteAndWait(async () =>
- {
- //Connect to the Discord server using our email and password
- await client.Connect(email, password);
- DebugMessage("Connected");
- //If we are not a member of any server, use our invite code (made beforehand in the official Discord Client)
- //if (!client.Servers.Any())
- // await client.AcceptInvite(client.GetInvite("aaabbbcccdddeee"));
- });
- }
- public static void DebugMessage(string message)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write("[Debug] ");
- Console.WriteLine(message);
- Console.ResetColor();
- }
- static void DebugMessage(string prefix, string message, ConsoleColor color)
- {
- Console.ForegroundColor = color;
- Console.Write("[{0}] ", prefix);
- Console.WriteLine(message);
- Console.ResetColor();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement