Advertisement
Guest User

Bot.cs

a guest
Oct 16th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using Discord;
  8.  
  9. namespace SelfBot
  10. {
  11.     class Program
  12.     {
  13.         public DiscordClient _client;
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             Console.Title = "Initializing...";
  18.             Console.InputEncoding = Console.OutputEncoding = Encoding.Unicode;
  19.             Program bot = new Program();
  20.             try
  21.             {
  22.                 UserInfo user = LoadUser(args[0]);
  23.                 bot.LogIn(user);
  24.             }
  25.             catch (Exception e)
  26.             {
  27.                 Console.WriteLine($"[EXCEPTION]: {e.Message}\n\nProgram will now TRY to safely exit. Press any key to continue.)");
  28.             }
  29.  
  30.             Console.ReadKey();
  31.         }
  32.  
  33.         private void LogIn(UserInfo user)
  34.         {
  35.             _client = new DiscordClient(x =>
  36.             {
  37.                 x.AppName = "Purple Ice's Bot";
  38.                 x.LogLevel = LogSeverity.Error;
  39.                 x.LogHandler = Log;
  40.             });
  41.  
  42.             _client.MessageReceived += (async (s, e) =>
  43.             {
  44.                 if (e.Message.IsAuthor)
  45.                 {
  46.                     _client.SetGame($"[{DateTime.Now.Hour,0:D2}:{DateTime.Now.Minute,0:D2}]");
  47.                 }
  48.                 if (e.Message.User.Id == 194152334312472577 && e.Channel.IsPrivate)
  49.                 {
  50.                     await e.Channel.SendMessage("I love you <3"); // hehe xd
  51.                 }
  52.             });
  53.  
  54.             _client.ExecuteAndWait(async () =>
  55.             {
  56.                 Console.Title = "Connecting...";
  57.                 await _client.Connect(user.email, user.password);
  58.                 Console.Title = $"{_client.CurrentUser.Name}";
  59.                 Console.WriteLine("Thanks <3\n\n\nI mean, it works.");
  60.             });
  61.         }
  62.  
  63.         private void Log(object sender, LogMessageEventArgs e)
  64.         {
  65.             Console.WriteLine($"[{e.Severity}] [{e.Source}] [{e.Message}]");
  66.         }
  67.  
  68.         private static UserInfo LoadUser(string path)
  69.         {
  70.             if (Path.GetExtension(path) != ".sbu")
  71.             {
  72.                 throw new Exception("This program supports only .sbu files.");
  73.             }
  74.             string[] lines = File.ReadAllLines(path, Encoding.UTF8);
  75.             return new UserInfo(lines[0], lines[1]);
  76.         }
  77.     }
  78.  
  79.     struct UserInfo
  80.     {
  81.         public string email { get; private set; }
  82.         public string password { get; private set; }
  83.  
  84.         public UserInfo(string email, string password)
  85.         {
  86.             this.email = email;
  87.             this.password = password;
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement