Archived
1
0
Fork 0
This repository has been archived on 2024-05-21. You can view files and clone it, but cannot push or open issues or pull requests.
maki/MakiTest/Program.cs

69 lines
5 KiB
C#
Raw Normal View History

2017-05-14 12:02:51 +00:00
using Maki;
using System;
using System.IO;
using System.Threading;
namespace MakiTest
{
class Program
{
static void Main(string[] args)
{
string[] tokenInfo = File.ReadAllLines("token.txt");
string token = tokenInfo[0] ?? string.Empty;
DiscordTokenType type = (tokenInfo[1] ?? string.Empty) == "user" ? DiscordTokenType.User : DiscordTokenType.Bot;
string username = string.Empty;
string password = string.Empty;
string mfaCode = null;
if (tokenInfo.Length >= 5)
{
username = tokenInfo[2];
password = tokenInfo[3];
mfaCode = tokenInfo[4];
}
else if (string.IsNullOrEmpty(token))
throw new Exception("Please set a token or login details.");
using (ManualResetEvent mre = new ManualResetEvent(false))
using (Discord client = new Discord())
{
Console.CancelKeyPress += (s, e) => { e.Cancel = true; mre.Set(); };
if (!string.IsNullOrEmpty(token))
client.Connect(token, type);
else
client.Connect(username, password, mfaCode);
client.OnReady += (me) => Console.WriteLine($"Connected as {me.NameWithTag} ({me.Id})!");
client.OnServerCreate += (serv) => Console.WriteLine($"Server {serv.Name} ({serv.Id}) created.");
client.OnServerUpdate += (serv) => Console.WriteLine($"Server {serv.Name} ({serv.Id}) updated.");
client.OnServerDelete += (serv) => Console.WriteLine($"Server {serv.Name} ({serv.Id}) deleted.");
client.OnEmojisUpdate += (serv) => Console.WriteLine($"Server {serv.Name} ({serv.Id}) emojis updated.");
client.OnChannelCreate += (chan) => Console.WriteLine($"Channel #{chan.Name} ({chan.Id}) in {chan.Server.Name} ({chan.Server.Id}) created.");
client.OnChannelUpdate += (chan) => Console.WriteLine($"Channel #{chan.Name} ({chan.Id}) in {chan.Server.Name} ({chan.Server.Id}) updated.");
client.OnChannelDelete += (chan) => Console.WriteLine($"Channel #{chan.Name} ({chan.Id}) in {chan.Server.Name} ({chan.Server.Id}) deleted.");
client.OnBanAdd += (user, serv) => Console.WriteLine($"{user.NameWithTag} ({user.Id}) been banned from {serv.Name} ({serv.Id}).");
client.OnBanRemove += (user, serv) => Console.WriteLine($"{user.NameWithTag} ({user.Id}) been unbanned from {serv.Name} ({serv.Id}).");
client.OnMemberAdd += (member) => Console.WriteLine($"{member.NameWithTag} ({member.User.Id}) joined {member.Server.Name} ({member.Server.Id}).");
client.OnMemberRemove += (member) => Console.WriteLine($"{member.NameWithTag} ({member.User.Id}) left {member.Server.Name} ({member.Server.Id}).");
client.OnMemberUpdate += (member) => Console.WriteLine($"{member.NameWithTag} ({member.User.Id}) was updated for {member.Server.Name} ({member.Server.Id}).");
client.OnMessageCreate += (msg) => Console.WriteLine($"{msg.Sender.NameWithTag} ({msg.Sender.User.Id}) in {msg.Channel.Server.Name} ({msg.Channel.Server.Id}) #{msg.Channel.Name} ({msg.Channel.Id}) {msg.Id}: {msg.Text}");
client.OnMessageUpdate += (msg) => Console.WriteLine($"{msg.Sender.NameWithTag} ({msg.Sender.User.Id}) in {msg.Channel.Server.Name} ({msg.Channel.Server.Id}) #{msg.Channel.Name} ({msg.Channel.Id}) {msg.Id}: {msg.Text}");
client.OnMessageDelete += (msg) => Console.WriteLine($"{msg.Sender.NameWithTag} ({msg.Sender.User.Id}) in {msg.Channel.Server.Name} ({msg.Channel.Server.Id}) #{msg.Channel.Name} ({msg.Channel.Id}) {msg.Id}");
client.OnRoleCreate += (role) => Console.WriteLine($"Role {role.Name} ({role.Id}) created in {role.Server.Name} ({role.Server.Id}).");
client.OnRoleUpdate += (role) => Console.WriteLine($"Role {role.Name} ({role.Id}) updated in {role.Server.Name} ({role.Server.Id}).");
client.OnRoleDelete += (role) => Console.WriteLine($"Role {role.Name} ({role.Id}) deleted in {role.Server.Name} ({role.Server.Id}).");
client.OnTypingStart += (user, chan) => Console.WriteLine($"{user.NameWithTag} ({user.User.Id}) started typing in #{chan.Name} ({chan.Id}) in {user.Server.Name} ({user.Server.Id})");
client.OnPresenceUpdate += (user) => Console.WriteLine($"Presence of {user.NameWithTag} ({user.User.Id}) update for {user.Server.Name} ({user.Server.Id}).");
client.OnUserUpdate += (user) => Console.WriteLine($"{user.NameWithTag} ({user.Id}) updated.");
mre.WaitOne();
}
Console.WriteLine("Stopped, press any key to close the program...");
Console.ReadKey();
}
}
}