Advertisement
LostProphet

Untitled

May 6th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Discord;
  2. using Discord.WebSocket;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace DiscordTest
  10. {
  11.     class Program
  12.     {
  13.         private static SocketGuild server;
  14.         private static SocketTextChannel channel;
  15.  
  16.         static void Main(string[] args)
  17.         {
  18.             DiscordSocketClient client = new DiscordSocketClient();
  19.             client.Log += OnLog;
  20.             client.GuildAvailable += ServerAvailable;
  21.             client.LoginAsync(Discord.TokenType.User, "ThisIsMyToken").Wait();
  22.             client.StartAsync().Wait();
  23.             Console.WriteLine("Connected: " + client.ConnectionState);
  24.  
  25.             bool exit = false;
  26.             while(!exit)
  27.             {
  28.                 string cmd = Console.ReadLine();
  29.  
  30.                 if(cmd == "/exit")
  31.                 {
  32.                     Console.WriteLine("Exiting...");
  33.                     exit = true;
  34.                 }
  35.                 else if(channel != null)
  36.                 {
  37.                     EmbedBuilder embed = new EmbedBuilder();
  38.                     embed.Url = "http://ragepluginhook.net/Downloads.aspx";
  39.                     embed.ThumbnailUrl = "http://ragepluginhook.net/images/HookLogoSmall.png";
  40.                     embed.Title = "The new RagePluginHook version is released!";
  41.                     embed.Color = new Color(/*0x70AEFF*/0x20ba0e);
  42.                     embed.Description = cmd;
  43.                    
  44.                     channel.SendMessageAsync(" ", false, embed).Wait();
  45.                     Console.WriteLine("Sent: " + cmd);
  46.                 }
  47.                 else
  48.                     Console.WriteLine("Server or channel not available");
  49.             }
  50.  
  51.             client.LogoutAsync().Wait();
  52.         }
  53.  
  54.         private static Task ServerAvailable(SocketGuild arg)
  55.         {
  56.             if(arg.Name.Contains("RAGE"))
  57.             {
  58.                 server = arg;
  59.  
  60.                 foreach(SocketTextChannel c in server.TextChannels)
  61.                 {
  62.                     if(c.Name == "moderation")
  63.                     {
  64.                         Console.WriteLine("Ready");
  65.                         channel = c;
  66.                     }
  67.                 }
  68.             }
  69.  
  70.             return null;
  71.         }
  72.  
  73.         private static Task OnLog(LogMessage arg)
  74.         {
  75.             ConsoleColor defaultColor = Console.ForegroundColor;
  76.             Console.ForegroundColor = GetSeverityColor(arg.Severity);
  77.             Console.Write("[" + arg.Source + '/' + arg.Severity + "] ");
  78.             Console.ForegroundColor = defaultColor;
  79.             Console.WriteLine(arg.Message);
  80.  
  81.             if(arg.Exception != null)
  82.                 Console.WriteLine(arg.Exception);
  83.  
  84.             return null;
  85.         }
  86.  
  87.         private static ConsoleColor GetSeverityColor(LogSeverity severity)
  88.         {
  89.             switch(severity)
  90.             {
  91.                 case LogSeverity.Critical:
  92.                 case LogSeverity.Error:
  93.                     return ConsoleColor.Red;
  94.                 case LogSeverity.Warning:
  95.                     return ConsoleColor.Yellow;
  96.                 case LogSeverity.Info:
  97.                     return ConsoleColor.White;
  98.                 case LogSeverity.Verbose:
  99.                 case LogSeverity.Debug:
  100.                     return ConsoleColor.DarkGray;
  101.             }
  102.  
  103.             return ConsoleColor.White;
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement