forked from DiscordUnity/DiscordUnity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiscordExample.cs
More file actions
129 lines (110 loc) · 3.38 KB
/
DiscordExample.cs
File metadata and controls
129 lines (110 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using UnityEngine;
using DiscordUnity;
using System.Linq;
public class DiscordExample : MonoBehaviour
{
private bool bot;
private string email;
private string password;
private string token;
private string serverName;
private string channelName;
private string filepath;
private DiscordClient client;
private DiscordTextChannel randomChannel;
private System.Diagnostics.Stopwatch timer;
void Start()
{
bot = false;
email = "email";
password = "password";
token = "token";
serverName = "server name";
channelName = "channel name";
filepath = "D://Documents//Pictures//MountainBackground.jpg";
client = new DiscordClient();
timer = new System.Diagnostics.Stopwatch();
client.OnMessageCreated += MessageCreated;
}
private void MessageCreated(object s, DiscordMessageArgs e)
{
if (e.message.author == client.user)
{
Debug.Log("We send: " + e.message.content);
}
}
private void ClientOpened(DiscordClient client, string result, DiscordError error)
{
if (error.failed)
{
Debug.LogError("Client failed to open: " + error.message);
return;
}
Debug.Log("Client opened.");
timer.Start();
}
private void ClientClosed(DiscordClient client, string result, DiscordError error)
{
if (error.failed)
{
Debug.LogError("Client failed to close: " + error.message);
return;
}
timer.Start();
timer.Stop();
Debug.Log("Client closed: " + timer.Elapsed.Seconds);
}
private void FileSend(DiscordClient client, string result, DiscordError error)
{
if (error.failed)
{
Debug.LogError("Client failed to close: " + error.message);
return;
}
Debug.Log("File send.");
}
void Update()
{
if (client.isOnline)
{
client.Update();
}
}
void OnGUI()
{
if (!client.isOnline)
{
bot = GUILayout.Toggle(bot, "Bot");
if (!bot)
{
email = GUILayout.TextField(email);
password = GUILayout.PasswordField(password, '*');
}
else
{
token = GUILayout.TextField(token);
}
if (GUILayout.Button("Start"))
{
if (!bot) client.Start(email, password, ClientOpened);
else client.StartBot(token, ClientOpened);
}
}
else
{
serverName = GUILayout.TextField(serverName);
channelName = GUILayout.TextField(channelName);
filepath = GUILayout.TextField(filepath);
if (GUILayout.Button("Send File"))
{
DiscordServer server = client.servers.Where(x => x.name == serverName).FirstOrDefault();
randomChannel = server.channels.Where(x => x.name == channelName).FirstOrDefault();
randomChannel.SendFile(filepath, FileSend);
}
if (GUILayout.Button("Stop"))
{
client.Stop(ClientClosed);
}
}
}
}