Advertisement
GuyWithAmp

Final Program.cs of Dicey v1 before she got better

Nov 15th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 31.01 KB | None | 0 0
  1. using Discord;
  2. using Discord.Audio;
  3. using Discord.Commands;
  4. using Discord.Commands.Permissions.Levels;
  5. using Discord.Modules;
  6. using System;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.IO;
  10. using DiscordBot.Commands;
  11.  
  12. namespace DiscordBot
  13. {
  14.     public class Program
  15.     {
  16.  
  17.         static string email = "";
  18.         static string password = "";
  19.         public static string path = System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("DiscordBot.exe", "");
  20.         public static string gameState = "idle";
  21.  
  22.         static void Main(string[] args)
  23.         {
  24.             string lastuser = "";
  25.             DebugMessage("Please input login email.");
  26.             Console.Write("  >");
  27.             email = Console.ReadLine();
  28.             DebugMessage("Please input login password.");
  29.             Console.Write("  >");
  30.             password = Console.ReadLine();
  31.             //ConsoleKey keyPressed = Console.ReadKey(true).Key;
  32.             //while(keyPressed != ConsoleKey.Enter)
  33.             //{
  34.             //    if (keyPressed != ConsoleKey.Backspace)
  35.             //    {
  36.             //        Console.Write('*');
  37.             //        password += keyPressed;
  38.             //    }
  39.             //    else
  40.             //    {
  41.             //        Console.Write("\b");
  42.             //        password += "\b";
  43.             //    }
  44.             //    keyPressed = Console.ReadKey(true).Key;
  45.             //}
  46.  
  47.             var client = new DiscordClient();
  48.  
  49.             var ponertimer = new System.Threading.Timer((e) =>
  50.             {
  51.                 PonerLand.Tick(client);
  52.             }, null, 0, (int)TimeSpan.FromMinutes(8).TotalMilliseconds);
  53.  
  54.             var questiontimer = new System.Threading.Timer((e) =>
  55.             {
  56.                 lastuser = "";
  57.             }, null, 0, (int)TimeSpan.FromMinutes(60).TotalMilliseconds);
  58.  
  59.             //Display all log messages in the console
  60.             client.Log.Message += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}");
  61.  
  62.             client.MessageReceived += (s, e) =>
  63.             {
  64.                 //Log messages
  65.                 DebugMessage("Log", string.Format("[{0}] {1}: {2}", e.Message.Timestamp, e.Message.User, e.Message.Text), ConsoleColor.DarkGray);
  66.                 LogCommand.AddLine(e.Message);
  67.  
  68.                 if (!e.Message.IsAuthor)
  69.                 {
  70.  
  71.                     //Things that can't be responded to chooser.
  72.                     if(e.Message.User.ToString() != "Choosie#9470")
  73.                     {
  74.                         /**if (e.Message.Text.ToLower().Contains("wew"))
  75.                         {
  76.                             e.Channel.SendMessage("lad");
  77.                             DebugMessage("A wew has been ladded.");
  78.                         }
  79.                         if (e.Message.Text.ToLower().Contains("lad"))
  80.                         {
  81.                             e.Channel.SendMessage("wew");
  82.                             DebugMessage("A lad has been wewed.");
  83.                         }*/
  84.                     }
  85.                     if (e.Message.Text.ToLower().EndsWith("?") && e.Message.User.Name == lastuser && !e.Message.Text.ToLower().Contains("choosie"))
  86.                     {
  87.                         e.Channel.SendMessage(RandomCommand.Fortune());
  88.                         bool temp = false;
  89.                         questiontimer = new System.Threading.Timer((f) =>
  90.                         {
  91.                             if (temp)
  92.                             {
  93.                                 lastuser = "";
  94.                             }
  95.                             else
  96.                             {
  97.                                 temp = true;
  98.                             }
  99.                         }, null, 0, (int)TimeSpan.FromMinutes(.5).TotalMilliseconds);
  100.                     }
  101.                     else {
  102.                         if (e.Message.Text.ToLower().StartsWith("dicey,"))
  103.                         {
  104.                             DebugMessage(lastuser);
  105.                             lastuser = e.Message.User.Name;
  106.                             DebugMessage(lastuser);
  107.                             e.Channel.SendMessage(RandomCommand.Fortune());
  108.  
  109.                             bool temp = false;
  110.                             questiontimer = new System.Threading.Timer((f) =>
  111.                             {
  112.                                 if (temp)
  113.                                 {
  114.                                     lastuser = "";
  115.                                 }
  116.                                 else
  117.                                 {
  118.                                     temp = true;
  119.                                 }
  120.                             }, null, 0, (int)TimeSpan.FromMinutes(.5).TotalMilliseconds);
  121.                         }
  122.                     }
  123.  
  124.  
  125.                     //Commands
  126.                     if (e.Message.Text.StartsWith("?"))
  127.                     {
  128.                         DebugMessage(string.Format("[{0}] has just called {1}", e.Message.User, e.Message.Text));
  129.                         string[] command = e.Message.Text.Replace("?", "").Split();
  130.                         if (gameState == "idle")
  131.                         {
  132.                             switch (command[0])
  133.                             {
  134.                                 //case "wake":
  135.                                 //    if (command.Length > 1)
  136.                                 //    {
  137.                                 //        if (command[1] != "")
  138.                                 //        {
  139.                                 //            e.Channel.SendMessage(string.Format("Hey @{0}, get up!", command[1]));
  140.                                 //        }
  141.                                 //        else
  142.                                 //        {
  143.                                 //            e.Channel.SendMessage("I'm already up, dumbass.");
  144.                                 //        }
  145.                                 //    }
  146.                                 //    break;
  147.                                 case "exit":
  148.                                     if (e.Message.User.Id == 135822482895536128)
  149.                                     {
  150.                                         Environment.Exit(0);
  151.                                     }
  152.                                     break;
  153.                                 case "fortune":
  154.                                     e.Channel.SendMessage(RandomCommand.Fortune());
  155.                                     break;
  156.                                 case "roll":
  157.                                     if (command.Length > 1 && command[1].Contains("d"))
  158.                                     {
  159.                                         Random r = new Random();
  160.                                         string die = command[1];
  161.                                         int mod = 0;
  162.                                         if (command[1].Contains("+"))
  163.                                         {
  164.                                             die = command[1].Split('+')[0];
  165.                                             int.TryParse(command[1].Split('+')[1], out mod);
  166.                                         }
  167.                                         //bool negative = false;
  168.                                         if (command[1].StartsWith("-"))
  169.                                         {
  170.                                             //negative = true;
  171.                                             command[1] = command[1].Substring(1);
  172.                                         }
  173.                                         if (command[1].Contains("-"))
  174.                                         {
  175.                                             die = command[1].Split('-')[0];
  176.                                             int.TryParse(command[1].Split('-')[1], out mod);
  177.                                             mod = -mod;
  178.                                         }
  179.                                         int count;
  180.                                         int.TryParse(die.Split('d')[0], out count);
  181.  
  182.                                         int sides;
  183.                                         int.TryParse(die.Split('d')[1], out sides);
  184.                                         if (count <= 9999999 && sides <= 9999999)
  185.                                         {
  186.                                             int[] results = new int[Math.Abs(count)];
  187.                                             int sum = 0;
  188.                                             if (count > 0)
  189.                                             {
  190.                                                 for (int i = 0; i < count; i++)
  191.                                                 {
  192.                                                     results[i] = r.Next(sides) + 1;
  193.                                                     sum += results[i];
  194.                                                 }
  195.                                             }
  196.                                             else
  197.                                             {
  198.                                                 for (int i = 0; i > count; i--)
  199.                                                 {
  200.                                                     results[Math.Abs(i)] = -r.Next(sides) - 1;
  201.                                                     sum += results[Math.Abs(i)];
  202.                                                 }
  203.                                             }
  204.                                             sum += mod;
  205.                                             if (count > 100 || sides > 1000)
  206.                                             {
  207.                                                 e.Channel.SendMessage(string.Format("{0} = [Compressed due to size]", sum));
  208.                                             }
  209.                                             else
  210.                                             {
  211.                                                 e.Channel.SendMessage(string.Format("{2} = [{0} + {1}]", string.Join(" + ", results), mod, sum));
  212.                                             }
  213.                                         }
  214.                                     }
  215.                                     break;
  216.                                 //case "kill":
  217.                                 //    if (command.Length > 1)
  218.                                 //    {
  219.                                 //        if (command[1] != "")
  220.                                 //        {
  221.                                 //            if (command[1].ToLower() == "dicey")
  222.                                 //            {
  223.                                 //                e.Channel.SendMessage("You fucker.");
  224.                                 //            }
  225.                                 //            if (e.Message.User.Id == 135822482895536128)
  226.                                 //            {
  227.                                 //                PonerLand.Kill(command[1].ToLower());
  228.                                 //                e.Channel.SendMessage(command[1].Replace('_', ' ') + " is dead.");
  229.                                 //            }
  230.                                 //            else
  231.                                 //            {
  232.                                 //                e.Channel.SendMessage("You are not allowed to kill poners.");
  233.                                 //            }
  234.                                 //        }
  235.                                 //    }
  236.                                 //    else
  237.                                 //    {
  238.                                 //        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."}));
  239.                                 //    }
  240.                                 //    break;
  241.                                 case "bully":
  242.                                 case "billy":
  243.                                     if (command.Length > 1)
  244.                                     {
  245.                                         if (command[1] != "")
  246.                                         {
  247.                                             if (command[1].ToLower() == "me")
  248.                                             {
  249.                                                 if (e.Message.User.Nickname != "")
  250.                                                 {
  251.                                                     command[1] = e.Message.User.Nickname.ToLower();
  252.                                                 }
  253.                                                 else
  254.                                                 {
  255.                                                     command[1] = e.Message.User.Name.ToLower();
  256.                                                 }
  257.                                             }
  258.                                             if (command[1].ToLower() == "you")
  259.                                                 command[1] = "Dicey";
  260.                                             e.Channel.SendMessage(BillyCommand.GetBilly(command[1]));
  261.                                         }
  262.                                         else
  263.                                         {
  264.                                             e.Channel.SendMessage("Fuck you, spacebar.");
  265.                                         }
  266.  
  267.                                     }
  268.                                     else
  269.                                     {
  270.                                         e.Channel.SendMessage("You all are disgraces that shouldn't feel happiness.");
  271.                                     }
  272.                                     break;
  273.                                 case "random":
  274.                                     if (command.Length > 1)
  275.                                     {
  276.                                         string[] tokens = new string[command.Length - 1];
  277.                                         for (int i = 1; i < command.Length; i++)
  278.                                         {
  279.                                             tokens[i - 1] = command[i];
  280.                                         }
  281.                                         string joined = string.Join(" ", tokens);
  282.                                         tokens = joined.Split(',');
  283.                                         e.Channel.SendMessage("[`" + RandomCommand.Random(tokens).Trim() + "`]");
  284.  
  285.                                     }
  286.                                     break;
  287.                                 case "help":
  288.                                     e.Channel.SendMessage("Generic Commands:\n\t?help, Displays Commands\n\t?random, Chooses a random string from a list given. Separated by commas" +
  289.                                         "\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" +
  290.                                         "\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." +
  291.                                         "\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.");
  292.                                     break;
  293.                                 case "boop":
  294.                                 case "newspaper":
  295.                                     //if (command.Length > 1)
  296.                                     //{
  297.                                     //    if(command[1] != "")
  298.                                     //    {
  299.                                     //        if(command[1].ToLower() == "dicey")
  300.                                     //        {
  301.                                     //            e.Channel.SendMessage("[scrunch]");
  302.                                     //        }
  303.                                     //        e.Channel.SendMessage(PonerLand.Boop(command[1].ToLower().Replace('_', ' '), e.Message.User.Nickname));
  304.                                     //    }
  305.                                     //}
  306.                                     //else
  307.                                     //{
  308.                                     e.Channel.SendMessage("[scrunch]");
  309.                                     //}
  310.                                     break;
  311.                                 case "hug":
  312.                                     //if (command.Length > 1)
  313.                                     //{
  314.                                     //    if (command[1] != "")
  315.                                     //    {
  316.                                     //        if (command[1].ToLower() == "dicey")
  317.                                     //        {
  318.                                     //            e.Channel.SendMessage("I can't hug myself, stupid.");
  319.                                     //        }
  320.                                     //        else {
  321.                                     //            e.Channel.SendMessage(PonerLand.Hug(command[1].ToLower().Replace('_', ' '), e.Message.User.Nickname));
  322.                                     //        }
  323.                                     //    }
  324.                                     //}
  325.                                     //else
  326.                                     //{
  327.                                     e.Channel.SendMessage("[hug]");
  328.                                     //}
  329.                                     break;
  330.                                 case "brushie":
  331.                                     //if (command.Length > 1)
  332.                                     //{
  333.                                     //    if (command[1] != "")
  334.                                     //    {
  335.                                     //        if (command[1].ToLower() == "dicey")
  336.                                     //        {
  337.                                     //            e.Channel.SendMessage("[pleased dicey noises]");
  338.                                     //        }
  339.                                     //        e.Channel.SendMessage(PonerLand.Brushie(command[1].ToLower().Replace('_', ' '), e.Message.User.Nickname));
  340.                                     //    }
  341.                                     //}
  342.                                     //else
  343.                                     //{
  344.                                     e.Channel.SendMessage("[pleased dicey noises]");
  345.                                     //}
  346.                                     break;
  347.                                 case "feed":
  348.                                     //if (command.Length > 1)
  349.                                     //{
  350.                                     //    if (command[1] != "")
  351.                                     //    {
  352.                                     //        if (command[1].ToLower() == "dicey")
  353.                                     //        {
  354.                                     //            e.Channel.SendMessage("");
  355.                                     //        }
  356.                                     //        e.Channel.SendMessage(PonerLand.Feed(command[1].ToLower().Replace('_', ' '), e.Message.User.Nickname));
  357.                                     //    }
  358.                                     //}
  359.                                     //else
  360.                                     //{
  361.                                     e.Channel.SendMessage("[pleased dicey noises]");
  362.                                     //}
  363.                                     break;
  364.                                 //case "ponies":
  365.                                 //case "poners":
  366.                                 //    e.Channel.SendMessage("```" + string.Join("\n", PonerLand.GetPoners()).Replace('_', ' ') + "```");
  367.                                 //    break;
  368.                                 //case "new":
  369.                                 //    if (command.Length > 1)
  370.                                 //    {
  371.                                 //        PonerLand.NewPoner(command[1], e.Message);
  372.                                 //    }
  373.                                 //    break;
  374.                                 //case "ded":
  375.                                 //case "dead":
  376.                                 //    e.Channel.SendMessage("```" + string.Join(", ", PonerLand.GetDed()).Replace('_', ' ') + "```");
  377.                                 //    break;
  378.                                 case "battleship":
  379.                                     gameState = "battleship";
  380.                                     Battleship.StartGame(e.Server);
  381.                                     break;
  382.  
  383.                             }
  384.                         }
  385.                         if (gameState == "battleship")
  386.                         {
  387.                             switch(command[0])
  388.                             {
  389.                                 case "help":
  390.                                     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.");
  391.                                     break;
  392.                                 case "quit":
  393.                                     gameState = "idle";
  394.                                     break;
  395.                                 case "shoot":
  396.                                     if (Battleship.gameState == "playing")
  397.                                     {
  398.                                         if (command[1] != null)
  399.                                         {
  400.                                             int row;
  401.                                             bool correct = int.TryParse(command[1].Substring(1), out row);
  402.                                             int column;
  403.                                             switch (command[1].ToLower()[0])
  404.                                             {
  405.                                                 case 'a':
  406.                                                     column = 0;
  407.                                                     break;
  408.                                                 case 'b':
  409.                                                     column = 1;
  410.                                                     break;
  411.                                                 case 'c':
  412.                                                     column = 2;
  413.                                                     break;
  414.                                                 case 'd':
  415.                                                     column = 3;
  416.                                                     break;
  417.                                                 case 'e':
  418.                                                     column = 4;
  419.                                                     break;
  420.                                                 case 'f':
  421.                                                     column = 5;
  422.                                                     break;
  423.                                                 case 'g':
  424.                                                     column = 6;
  425.                                                     break;
  426.                                                 case 'h':
  427.                                                     column = 7;
  428.                                                     break;
  429.                                                 case 'i':
  430.                                                     column = 8;
  431.                                                     break;
  432.                                                 case 'j':
  433.                                                     column = 9;
  434.                                                     break;
  435.                                                 default:
  436.                                                     column = 10;
  437.                                                     break;
  438.                                             }
  439.                                             if (correct && column < 10 && column >= 0)
  440.                                             {
  441.                                                 Battleship.Turn(e.Server, row - 1, column);
  442.                                             }
  443.                                             else
  444.                                             {
  445.                                                 e.Channel.SendMessage("That's not how you say it, dumbass. It's letter, then number. Like A1, or E10. No space inbetween.");
  446.                                             }
  447.                                         }
  448.                                         else
  449.                                         {
  450.                                             e.Channel.SendMessage("Bang! Oh, you wanted to shoot somewhere specific. Why didn't you say so?");
  451.                                         }
  452.                                     }
  453.                                     else
  454.                                     {
  455.                                         e.Channel.SendMessage("You can't shoot 'till the game's started, dummy.");
  456.                                     }
  457.                                     break;
  458.                                 case "place":
  459.                                     if (Battleship.gameState == "placing")
  460.                                     {
  461.                                         if (command[1] != null)
  462.                                         {
  463.                                             int row;
  464.                                             bool correct = int.TryParse(command[1].Substring(1), out row);
  465.                                             int column;
  466.                                             switch (command[1].ToLower()[0])
  467.                                             {
  468.                                                 case 'a':
  469.                                                     column = 0;
  470.                                                     break;
  471.                                                 case 'b':
  472.                                                     column = 1;
  473.                                                     break;
  474.                                                 case 'c':
  475.                                                     column = 2;
  476.                                                     break;
  477.                                                 case 'd':
  478.                                                     column = 3;
  479.                                                     break;
  480.                                                 case 'e':
  481.                                                     column = 4;
  482.                                                     break;
  483.                                                 case 'f':
  484.                                                     column = 5;
  485.                                                     break;
  486.                                                 case 'g':
  487.                                                     column = 6;
  488.                                                     break;
  489.                                                 case 'h':
  490.                                                     column = 7;
  491.                                                     break;
  492.                                                 case 'i':
  493.                                                     column = 8;
  494.                                                     break;
  495.                                                 case 'j':
  496.                                                     column = 9;
  497.                                                     break;
  498.                                                 default:
  499.                                                     column = 10;
  500.                                                     break;
  501.                                             }
  502.                                             int dir = 0;
  503.                                             int.TryParse(command[2], out dir);
  504.                                             if (correct && column < 10 && column >= 0 && dir != 0)
  505.                                             {
  506.                                                 Battleship.PlacePlayerShip(e.Server, row - 1, column, dir);
  507.                                             }
  508.                                             else
  509.                                             {
  510.                                                 e.Channel.SendMessage("Example, ?place A1 3, which would place a ship in the top left corner facing down.");
  511.                                             }
  512.                                         }
  513.                                         else
  514.                                         {
  515.                                             e.Channel.SendMessage("Example, ?place A1 3, which would place a ship in the top left corner facing down.");
  516.                                         }
  517.                                     }
  518.                                     else
  519.                                     {
  520.                                         e.Channel.SendMessage("You already placed them, though!");
  521.                                     }
  522.                                     break;
  523.  
  524.                             }
  525.                         }
  526.                     }
  527.                 }
  528.             };
  529.  
  530.  
  531.             //Echo back any message received, provided it didn't come from the bot itself
  532.             /**client.MessageReceived += async (s, e) =>
  533.             {
  534.                 if (!e.Message.IsAuthor)
  535.                 {
  536.                     await e.Channel.SendMessage(e.Message.Text);
  537.                 }
  538.             };*/
  539.             //Convert our sync method to an async one and block the Main function until the bot disconnects
  540.             client.ExecuteAndWait(async () =>
  541.             {
  542.                 //Connect to the Discord server using our email and password
  543.                 await client.Connect(email, password);
  544.                 DebugMessage("Connected");
  545.                 //If we are not a member of any server, use our invite code (made beforehand in the official Discord Client)
  546.                 //if (!client.Servers.Any())
  547.                 //    await client.AcceptInvite(client.GetInvite("aaabbbcccdddeee"));
  548.             });
  549.  
  550.  
  551.         }
  552.  
  553.         public static void DebugMessage(string message)
  554.         {
  555.             Console.ForegroundColor = ConsoleColor.Green;
  556.             Console.Write("[Debug] ");
  557.             Console.WriteLine(message);
  558.             Console.ResetColor();
  559.         }
  560.  
  561.         static void DebugMessage(string prefix, string message, ConsoleColor color)
  562.         {
  563.             Console.ForegroundColor = color;
  564.             Console.Write("[{0}] ", prefix);
  565.             Console.WriteLine(message);
  566.             Console.ResetColor();
  567.         }
  568.     }
  569. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement