private async Task Client_MessageReceived(SocketMessage arg) { try { RuntimeMessage r = new RuntimeMessage(arg, Client.GetShardFor((((arg as IUserMessage).Channel) as IGuildChannel).Guild)); if (r.Content.Contains(r.Bot.Id.ToString())) { await Events.OnMention(r); } if (r.Guild != null) { await Events.OnMessageRecieved(r); } else { await Events.OnPrivateMessage(r); } } catch (Exception e) { Log.ErrorAt("messagerecieved", e.Message); } }
public void LoadEvents() { Client.UserJoined += async(u) => { Task.Run(() => UserJoin?.Invoke(new RuntimeUser(u))); }; Client.UserLeft += async(u) => { Task.Run(() => UserLeft?.Invoke(new RuntimeUser(u))); }; Client.UserUpdated += async(u, unew) => { RuntimeUser userOld = new RuntimeUser(u); RuntimeUser userNew = new RuntimeUser(unew); Task.Run(() => UserUpdated?.Invoke(userOld, userNew)); }; Client.MessageReceived += async(m) => { RuntimeMessage newMessage = new RuntimeMessage(m); if (MessageReceived != null) { await MessageReceived.Invoke(newMessage); } }; Client.JoinedGuild += async(g) => { Task.Run(async() => { RuntimeGuild guild = new RuntimeGuild(g); await GuildJoin?.Invoke(guild); }); }; Client.LeftGuild += async(g) => { RuntimeGuild guild = new RuntimeGuild(g); await GuildLeave?.Invoke(guild); }; foreach (var shard in Client.Shards) { shard.Disconnected += async(ex) => { await OnShardDisconnect?.Invoke(ex, shard.ShardId); }; shard.Connected += async() => { if (OnShardConnect != null) { await OnShardConnect.Invoke(shard.ShardId); } }; } }
private async Task Module_MessageRecieved(IMessage message) { RuntimeMessage msg = new RuntimeMessage(message); if (await IsEnabled(msg.Guild.Id)) { try { await MessageRecieved(msg); } catch (Exception ex) { Log.ErrorAt("module@message", ex.Message); } } }
public void LoadEvents() { Client.UserJoined += async(u) => { await MeruUtils.TryAsync(async() => { Task.Run(() => UserJoin?.Invoke(new RuntimeUser(u))); }); }; Client.UserLeft += async(u) => { await MeruUtils.TryAsync(async() => { Task.Run(() => UserLeft?.Invoke(new RuntimeUser(u))); }); }; Client.UserUpdated += async(u, unew) => { RuntimeUser userOld = new RuntimeUser(u); RuntimeUser userNew = new RuntimeUser(unew); Task.Run(() => UserUpdated?.Invoke(userOld, userNew)); }; Client.MessageReceived += async(m) => { Task.Run(async() => { await MeruUtils.TryAsync(async() => { RuntimeMessage newMessage = new RuntimeMessage(m); await MessageReceived?.Invoke(newMessage); }); }); }; }
private async Task OnMessageRecieved(DiscordSocketClient c, IMessage m) { IDiscordMessage msg = new RuntimeMessage(m); await MessageRecieved.Invoke(msg); }