protected override async Task UserJoined(SocketGuildUser user) { SetContext(new MethodContext(user.Guild, null, null)); if (!string.IsNullOrEmpty(Config.WelcomeMessage)) { await user.SendMessageAsync(Config.WelcomeMessage); } await LogModule.LogMessage($"{user.Username} has joined the server.", "recruitment"); }
/// <summary> /// Job for sending a discord message ten minutes before a moon is about to pop. /// </summary> /// <param name="job"></param> /// <param name="context"></param> /// <returns></returns> Task MoonPoppedJob(MoonJob job, MethodContext context) { SystemMoon moon = this.MoonParser.Parse(job.Moon.Split(' ')); if (TryGetMoon(moon, out MoonComposition comp)) { return(LogModule.LogMessage(Config.MoonPingMessage, Config.MoonPingChannel, embed: comp.PrettyMoon())); } return(Task.CompletedTask); }
/// <summary> /// Verify that a discord users nickname is the same as his EVE name. Change it if there is a mismatch. /// </summary> /// <param name="user"></param> /// <param name="eveId"></param> /// <returns></returns> async Task VerifyName(IGuildUser user, int eveId) { IApiResponse response = await ApiModule.Esi.Path("/characters/{character_id}/").Get(("character_id", eveId)); if (response is ApiError) { return; } dynamic casted = JsonConvert.DeserializeObject <dynamic>(response.FirstPage); string userName = string.IsNullOrEmpty(user.Nickname) ? user.Username : user.Nickname; string eveName = casted["name"].Value.ToString(); if (userName != eveName) { await user.ModifyAsync(x => x.Nickname = eveName); await LogModule.LogMessage($"Updated nickname for {userName} to {eveName}", Config.LogChannel); } }
/// <summary> /// Loop for receiving commands from the bovril auth website. /// </summary> /// <returns></returns> async Task SocketServer(IGuild guild) { // Website is hosted on he same network. IPAddress ipAdress = IPAddress.Parse("127.0.0.1"); IPEndPoint localEndPoint = new IPEndPoint(ipAdress, 55766); Socket listener = new Socket(ipAdress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); listener.Bind(localEndPoint); listener.Listen(100); while (true) { Socket socket = await listener.AcceptAsync(); string command = await ReveiceMessage(socket); await LogModule.LogMessage($"Received command '{command}' from auth server.", "debug"); await ProcessRequest(command, guild); } }
protected override async Task Init() { await LogAsync(YahurrFramework.Enums.LogLevel.Message, $"Initializing {this.GetType().Name}..."); ApiModule = await GetModuleAsync <ApiModule>(); LogModule = await GetModuleAsync <LogModule>(); webSocket = new ClientWebSocket(); zkillLoopToken = new CancellationTokenSource(); await LogAsync(YahurrFramework.Enums.LogLevel.Message, $"Connecting to zkill..."); if (await TryConnectWebSocket(CancellationToken.None)) { await LogAsync(YahurrFramework.Enums.LogLevel.Message, $"Starting zkill monitor loop..."); await StartZkillLoop(zkillLoopToken.Token); } else { await LogAsync(YahurrFramework.Enums.LogLevel.Error, "Unable to connect to zkill websocket api."); } }
protected override Task UserLeft(SocketGuildUser user) { SetContext(new MethodContext(user.Guild, null, null)); return(LogModule.LogMessage($"{user.Username} has left the server.", "recruitment")); }
/// <summary> /// Method to inform recruites when there is time for a checkup. /// </summary> /// <param name="job"></param> /// <param name="context"></param> /// <returns></returns> Task CheckupJobMethod(CheckupJob job, MethodContext context) { return(LogModule.LogMessage($"{job.Character} has been in corp for 30 days. Time for a checkup.", Config.CheckupLogChannel)); }
/// <summary> /// Remove a role from a user /// </summary> /// <param name="user"></param> /// <param name="role"></param> /// <returns></returns> async Task RemoveActualRole(IGuildUser user, ulong role) { IRole roleInstance = Guild.GetRole(role); await user.RemoveRoleAsync(roleInstance); await LogModule.LogMessage($"Role '{roleInstance.Name}' removed from {UserOrNickname(user)}", Config.LogChannel); }
/// <summary> /// Add a role to a user. /// </summary> /// <param name="user"></param> /// <param name="role"></param> /// <returns></returns> async Task AddActualRole(IGuildUser user, ulong role) { IRole roleInstance = Guild.GetRole(role); await user.AddRoleAsync(roleInstance); await LogModule.LogMessage($"Role '{roleInstance.Name}' added to {UserOrNickname(user)}", Config.LogChannel); }