private async Task HandleParting(SocketGuildUser user) { ServerGreeting shouldGreet = GetGreeting(user); if (shouldGreet != null && shouldGreet.GreetUsers == true) { ISocketMessageChannel messageChannel = null; if (shouldGreet.GreetingChannelId != 0) { messageChannel = user.Guild.GetChannel((ulong)shouldGreet.GreetingChannelId) as ISocketMessageChannel; } else { messageChannel = user.Guild.DefaultChannel as ISocketMessageChannel; } if (messageChannel != null) { var embed = new EmbedBuilder(); embed.Title = $"[{user.Username}] has left [**{user.Guild.Name}**]!"; if (string.IsNullOrEmpty(shouldGreet.PartingMessage)) { embed.Description = $"Fine, be that way! :wave:"; } else { embed.Description = shouldGreet.PartingMessage; } embed.ThumbnailUrl = user.GetAvatarUrl(); embed.WithColor(new Color(255, 0, 0)); await messageChannel.SendMessageAsync("", false, embed); } } }
public async Task ForceGreetingClear([Remainder] long serverId) { ServerGreeting greetingInfo = null; using (var db = new NinjaBotEntities()) { greetingInfo = db.ServerGreetings.Where(g => g.DiscordGuildId == serverId).FirstOrDefault(); } if (greetingInfo != null) { try { using (var db = new NinjaBotEntities()) { db.Remove(db.ServerGreetings.Where(g => g.DiscordGuildId == serverId).FirstOrDefault()); await db.SaveChangesAsync(); } await _cc.Reply(Context, "Cleared!"); } catch (Exception ex) { await _cc.Reply(Context, $"Error clearing greeting -> [{ex.Message}]"); } } else { await _cc.Reply(Context, $"No association found for [{serverId}]!"); } }
private async Task HandleGreeting(SocketGuildUser user) { //Maybe new ver of reply in ChannelCheck class? ServerGreeting shouldGreet = GetGreeting(user); if (shouldGreet != null && shouldGreet.GreetUsers == true) { StringBuilder sb = new StringBuilder(); ISocketMessageChannel messageChannel = null; if (shouldGreet.GreetingChannelId != 0) { messageChannel = user.Guild.GetChannel((ulong)shouldGreet.GreetingChannelId) as ISocketMessageChannel; } else { messageChannel = user.Guild.DefaultChannel as ISocketMessageChannel; } var embed = new EmbedBuilder(); embed.Title = $"[{user.Username}] has joined [**{user.Guild.Name}**]!"; if (string.IsNullOrEmpty(shouldGreet.Greeting)) { sb.AppendLine($"Welcome them! :hugging:"); sb.AppendLine($"(or not, :shrug:)"); embed.Description = sb.ToString(); } else { embed.Description = shouldGreet.Greeting; } embed.ThumbnailUrl = user.GetAvatarUrl(); embed.WithColor(new Color(0, 255, 0)); await messageChannel.SendMessageAsync("", false, embed); } }
private ServerGreeting GetGreeting(SocketGuildUser user) { ServerGreeting shouldGreet = null; var guildId = user.Guild.Id; using (var db = new NinjaBotEntities()) { shouldGreet = db.ServerGreetings.Where(g => g.DiscordGuildId == (long)guildId).FirstOrDefault(); } return shouldGreet; }
private ServerGreeting GetGreeting(SocketGuildUser user) { ServerGreeting shouldGreet = null; var guildId = user.Guild.Id; using (var db = new DiscbotContext()) { shouldGreet = db.ServerGreetings.AsEnumerable().Where(g => g.DiscordGuildId == (long)guildId).FirstOrDefault(); } return(shouldGreet); }
/// <summary> /// Performs the client/server handshake upon connecting to a CDDB server /// </summary> /// <param name="status">Not used</param> private void performClientServerHandshake(object status) { try { this.protocol = new CddbProtocol(this.socket); // Receive the server greeting string. This is sent by the CDDB server to // any client as soon as it connects and contains the server status and // software running on the server string greetingLine = this.protocol.ReceiveLine(5000); OnProgressAchieved(0.6f); // Obtain the status code returned from the server and convert it to // an exception if it indicates an error int greetingStatusCode = CddbProtocol.GetStatusCode(greetingLine); this.exception = exceptionFromGreetingStatus( greetingStatusCode, greetingLine.Substring((greetingLine.Length >= 4) ? 4 : 3) ); // If no error has occured, decode the server greeting string if(this.exception == null) { ServerGreeting greeting = decodeServerGreeting(greetingLine); // The server greeting was decoded successfully, now let's identify ourselves // to the CDDB server sendHello(); OnProgressAchieved(0.8f); // Receive the reply to our 'hello' from the server receiveHelloReply(); // If everything went fine the CDDB connection is ready to enter normal service if(this.exception == null) { this.connection = new CddbConnection( protocol, greeting.Hostname, greeting.Version, (greetingStatusCode == 201) // Read only connection? ); } } } catch(ObjectDisposedException exception) { if(!(this.exception is AbortedException)) { this.exception = exception; } } catch(Exception exception) { this.exception = exception; } OnAsyncEnded(); }
private async Task HandleParting(SocketGuildUser user) { await Task.Run(async () => { ServerGreeting shouldGreet = GetGreeting(user); if (shouldGreet != null && shouldGreet.GreetUsers == true) { var sb = new StringBuilder(); ISocketMessageChannel messageChannel = null; try { if (shouldGreet.GreetingChannelId != 0) { messageChannel = user.Guild.GetChannel((ulong)shouldGreet.GreetingChannelId) as ISocketMessageChannel; } else { messageChannel = user.Guild.DefaultChannel as ISocketMessageChannel; } if (messageChannel != null) { var embed = new EmbedBuilder(); embed.Title = $"[{user.Username}] has left [**{user.Guild.Name}**]!"; sb.AppendLine($"{user.Mention}"); if (string.IsNullOrEmpty(shouldGreet.PartingMessage)) { sb.AppendLine($"Fine, be that way! :wave:"); } else { sb.AppendLine($"{shouldGreet.PartingMessage}"); } embed.Description = sb.ToString(); embed.ThumbnailUrl = user.GetAvatarUrl(); embed.WithColor(new Color(255, 0, 0)); await messageChannel.SendMessageAsync("", false, embed.Build()); } } catch (Exception ex) { if (messageChannel != null) { _logger.LogError($"Error with channel -> [{messageChannel.Name}] on [{user.Guild.Name}] -> [{user.Guild.Id}] -> [{ex.Message}]"); } else { _logger.LogError($"Error with no channel -> [{user.Guild.Name}] -> [{user.Guild.Id}] -> [{ex.Message}]"); } } } }); }
/// <summary> /// Performs the initial greeting. /// </summary> /// <returns>The greeting-message returned by the SOCKS5 server.</returns> /// <exception cref="Socks5Exception">The server returned invalid or /// unexpected data.</exception> private ServerGreeting PerformGreeting() { var methods = new HashSet <AuthMethod>() { AuthMethod.None }; if (!String.IsNullOrEmpty(Username)) { methods.Add(AuthMethod.Username); } byte[] bytes = new ClientGreeting(methods).Serialize(); stream.Write(bytes, 0, bytes.Length); // Read the server's response. bytes = new byte[2]; stream.Read(bytes, 0, 2); return(ServerGreeting.Deserialize(bytes)); }
/// <summary> /// Performs the initial greeting. /// </summary> /// <exception cref="Socks5Exception">The client sent invalid data, or /// requires authentication.</exception> /// <exception cref="IOException">The stream could not be read, or the /// operation timed out.</exception> private void PerformGreeting() { ByteBuilder b = new ByteBuilder(); using (var r = new BinaryReader(stream, Encoding.UTF8, true)) { byte[] bytes = r.ReadBytes(2); b.Append(bytes); // The number of method-bytes following is contained in the second byte. b.Append(r.ReadBytes(bytes[1])); } ClientGreeting greeting = ClientGreeting.Deserialize(b.ToArray()); // We only accept an authentication method of 'none'. if (!greeting.Methods.Contains(AuthMethod.None)) { Dispose(); throw new Socks5Exception("Client requires authentication."); } // Send back our greeting response. var response = new ServerGreeting(AuthMethod.None).Serialize(); stream.Write(response, 0, response.Length); }