Advertisement
Guest User

bot1

a guest
Oct 13th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Discord;
  7. using Discord.WebSocket;
  8. using Newtonsoft.Json;
  9. using System.IO;
  10.  
  11. namespace DiscordBOT.Core
  12. {
  13.     internal static class onInput
  14.     {
  15.         private static Dictionary<string, string> dJson;
  16.         private static SocketTextChannel channel;
  17.         static string getJson(string key)
  18.         {
  19.             string json = File.ReadAllText("SystemLang/alerts.json");
  20.             var data = JsonConvert.DeserializeObject<dynamic>(json);
  21.             dJson = data.ToObject<Dictionary<string, string>>();
  22.             if (dJson.ContainsKey(key)) return dJson[key];
  23.             return "";
  24.         }
  25.         internal static Task reqInput()
  26.         {
  27.            
  28.             channel = Global.Client.GetGuild(Convert.ToUInt64(Utilities.GetAlert("GUILDID"))).GetTextChannel(Convert.ToUInt64(Utilities.GetAlert("CHANNELID")));
  29.  
  30.             ConsoleKeyInfo cki;
  31.             Console.ForegroundColor = ConsoleColor.Cyan;
  32.             /* MOTD */
  33.             Console.WriteLine("");
  34.             Console.WriteLine("++++++++++++++++++++++++++++++++++++");
  35.             Console.Write("+ ");
  36.             Console.WriteLine("Date: " + DateTime.Now.ToShortDateString() + " | Time: " + DateTime.Now.ToShortTimeString() + " +");
  37.             Console.WriteLine("+ Press CTRL to send a TTS via bot +");
  38.             Console.WriteLine("+ Press T to send a message via bot+");
  39.             Console.WriteLine("+ Press G to change the guild ID   +");
  40.             Console.WriteLine("+ Press C to change the channel ID +");
  41.             Console.WriteLine("+ Press S to clear stdOut (console)+");
  42.             Console.WriteLine("++++++++++++++++++++++++++++++++++++");
  43.             Console.ForegroundColor = ConsoleColor.Gray;
  44.             while (true)
  45.             {
  46.                 try
  47.                 {
  48.                     channel = Global.Client.GetGuild(Convert.ToUInt64(getJson("GUILDID"))).GetTextChannel(Convert.ToUInt64(getJson("CHANNELID")));
  49.                 } catch
  50.                 {
  51.                     Console.ForegroundColor = ConsoleColor.Red;
  52.                     Console.WriteLine("Error processing new Client information! Please check SystemLang/alerts.json!");
  53.                     Console.ForegroundColor = ConsoleColor.Gray;
  54.                 }
  55.                 cki = Console.ReadKey(true);
  56.                 char cCom = cki.KeyChar;
  57.                 if (cCom == 't' || cCom == 'T')
  58.                 {
  59.                     Console.WriteLine("Requesting Input...");
  60.                     Console.Write(">");
  61.                     Console.ForegroundColor = ConsoleColor.Yellow;
  62.                     string sInput = Console.ReadLine();
  63.                     send(sInput);
  64.                     Console.ForegroundColor = ConsoleColor.Gray;
  65.                 }
  66.                 else if ((cki.Modifiers.HasFlag(ConsoleModifiers.Control)))
  67.                 {
  68.                     {
  69.                         Console.WriteLine("Requesting TTS input...");
  70.                         channel.EnterTypingState();
  71.                         Console.Write(">");
  72.                         Console.ForegroundColor = ConsoleColor.Yellow;
  73.                         string sInput = Console.ReadLine();
  74.                         send(sInput, true);
  75.                         Console.ForegroundColor = ConsoleColor.Gray;
  76.                     }
  77.                 }
  78.                 else if (cCom == 'C' || cCom == 'c')
  79.                 {
  80.                     Console.WriteLine("Requesting new channel ID input... ");
  81.                     Console.Write(">");
  82.                     Console.ForegroundColor = ConsoleColor.Yellow;
  83.                     string sChannelID = Console.ReadLine();
  84.                     string json = File.ReadAllText("SystemLang/alerts.json");
  85.                     dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
  86.                     jsonObj["CHANNELID"] = sChannelID;
  87.                     string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
  88.                     File.WriteAllText("SystemLang/alerts.json", output);
  89.  
  90.                     Console.ForegroundColor = ConsoleColor.Cyan;
  91.                     Console.WriteLine("Applying changes...");
  92.  
  93.                     Console.ForegroundColor = ConsoleColor.Gray;
  94.                     Console.WriteLine("Done...!");
  95.  
  96.                 }
  97.                 else if (cCom == 'G' || cCom == 'g')
  98.                 {
  99.                     Console.WriteLine("Requesting new guild ID input... ");
  100.                     Console.Write(">");
  101.                     Console.ForegroundColor = ConsoleColor.Yellow;
  102.                     string sGuildID = Console.ReadLine();
  103.                     string json = File.ReadAllText("SystemLang/alerts.json");
  104.                     dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
  105.                     jsonObj["GUILDID"] = sGuildID;
  106.                     string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
  107.                     File.WriteAllText("SystemLang/alerts.json", output);
  108.  
  109.                     Console.ForegroundColor = ConsoleColor.Cyan;
  110.                     Console.WriteLine("Applying changes...");
  111.  
  112.                     Console.ForegroundColor = ConsoleColor.Gray;
  113.                     Console.WriteLine("Done...!");
  114.                 }
  115.                 else if (cCom == 'S' || cCom == 's')
  116.                 {
  117.                     Console.Clear();
  118.                 }
  119.             }
  120.             // return Task.CompletedTask;
  121.         }
  122.  
  123.         private static async void send(string sForward, bool tts = false)
  124.         {
  125.             /* if (Global.Client == null)
  126.              {
  127.                  Console.WriteLine("Client unready!");
  128.                  return;
  129.              }*/
  130.  
  131.             try
  132.             {
  133.  
  134.                
  135.                 await channel.SendMessageAsync(sForward, tts);
  136.             } catch
  137.             {
  138.                 if (sForward == "" || sForward == null)
  139.                 {
  140.                     Console.ForegroundColor = ConsoleColor.Red;
  141.                     Console.WriteLine("Input cannot be null!");
  142.                     Console.ForegroundColor = ConsoleColor.Gray;
  143.                 }
  144.             }
  145.         }
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement