public async Task RemovePin(IUserMessage message) { await message.UnpinAsync(); using (var db = data.GetContext()) { await db.RemovePin(message.Channel.Id, message.Id); } }
public async Task UnpinEventMessage(ISocketMessageChannel channel, Event @event) { if (@event.MessageId == null) { return; } IUserMessage msg = ((IUserMessage)await channel.GetMessageAsync(Convert.ToUInt64(@event.MessageId))); if (msg != null) { await msg.UnpinAsync(); } }
private async Task unpinMessage(IUserMessage message, ISocketMessageChannel channel, SocketReaction reaction, IUser user) { var client = Service.GetRequiredService <DiscordSocketClient>(); if (message.Author.Id != client.CurrentUser.Id) { return; } if (message.IsPinned) { await message.UnpinAsync().ConfigureAwait(false); } }
private async Task OnReactionRemoved(Cacheable <IUserMessage, ulong> msg, ISocketMessageChannel chan, SocketReaction reaction) { if (reaction.Emote.Name.Equals(PIN_EMOTE)) { IUserMessage m = (IUserMessage)await chan.GetMessageAsync(msg.Id); var ReactionList = m.Reactions; foreach (KeyValuePair <IEmote, ReactionMetadata> item in ReactionList) { if (item.Key.Name.Equals(PIN_EMOTE) && item.Value.ReactionCount <= PIN_THRESHOLD - 2) { await m.UnpinAsync(); } } } }
public async Task StopAsync() { if (!Program.AttendanceEvent.active) { await ReplyAsync("Unable to stop event, no event is running!"); return; } string _attendanceName = Program.AttendanceEvent.type + Config.Global.Commands.Attendance.AttendanceSuffix; string _excusedName = Program.AttendanceEvent.type + Config.Global.Commands.Attendance.ExcusedSuffix; int attendanceWeight = 0; int excusedWeight = 0; ValueRange readResult = await GoogleSheetsHelper.Instance.GetAsync(Config.Global.DKPReasonsTab); if (readResult.Values != null && readResult.Values.Count > 0) { int idx = GoogleSheetsHelper.Instance.IndexInRange(readResult, _attendanceName); if (idx >= 0) { int.TryParse(readResult.Values[idx][1].ToString(), out attendanceWeight); } idx = GoogleSheetsHelper.Instance.IndexInRange(readResult, _excusedName); if (idx >= 0) { int.TryParse(readResult.Values[idx][1].ToString(), out excusedWeight); } } string timestamp = DateTime.Now.ToString(); IList <IList <object> > writeValues = new List <IList <object> >(); foreach (string member in Program.AttendanceEvent.members) { writeValues.Add(new List <object> { member, attendanceWeight, timestamp, _attendanceName, Program.AttendanceEvent.note }); } foreach (string excused in Program.AttendanceEvent.excused) { writeValues.Add(new List <object> { excused, excusedWeight, timestamp, _excusedName, Program.AttendanceEvent.note }); } ValueRange writeBody = new ValueRange { Values = writeValues }; AppendValuesResponse writeResult = await GoogleSheetsHelper.Instance.AppendAsync(Config.Global.DKPLogTab, writeBody); int?result = writeResult.Updates.UpdatedCells; if (result <= 0) { await ReplyAsync($"Error writing DKP for event!"); } string message = $"Ended event {Program.AttendanceEvent.type} {Program.AttendanceEvent.note} with the following {Program.AttendanceEvent.members.Count} members attending: "; foreach (string member in Program.AttendanceEvent.members) { message += $"{member}, "; } if (Program.AttendanceEvent.excused.Count > 0) { message += $"and the following {Program.AttendanceEvent.excused.Count} member(s) excused: "; } foreach (string excused in Program.AttendanceEvent.excused) { message += $"{excused}, "; } message += "and that's all, folks!"; IUserMessage pin = await Context.Channel.GetMessageAsync(Program.AttendanceEvent.messageId) as IUserMessage; if (pin != null) { await pin.UnpinAsync(); } Program.AttendanceEvent = default(SAttendanceEvent); await Context.Channel.SendMessageAsync(message); }
public override async Task OnMessage(SocketMessage arg, Android android, bool editedMessage) { if (arg.Author.IsBot) { return; } foreach (var prefix in ModReleasePrefixes.OrderByDescending(c => c.Length)) { var simplifiedContent = arg.Content.Normalize().Trim().ToLower(); if (!simplifiedContent.StartsWith(prefix)) { continue; } var strippedDown = simplifiedContent.Remove(0, prefix.Length); string modName = ""; try { modName = strippedDown.Substring(0, strippedDown.IndexOf("\n")).Trim();; } catch (Exception) { await arg.Channel.SendMessageAsync("you need to give your mod a description or something under it"); break; } if (!arg.Attachments.Any(attachment => attachment.Filename.EndsWith(ModFileEnd))) { await arg.Channel.SendMessageAsync("mods have to provide a download link"); break; } if (CrudeModdingStorage.Current.IdentityMessageMap.TryGetValue(modName, out var messageId)) { IUserMessage existingReleaseMessage = (IUserMessage)await arg.Channel.GetMessageAsync(messageId); if (existingReleaseMessage.Author.Id != arg.Author.Id) { await arg.Channel.SendMessageAsync("mod name has been claimed by " + existingReleaseMessage.Author.Username); break; } await existingReleaseMessage.UnpinAsync(); CrudeModdingStorage.Current.IdentityMessageMap[modName] = arg.Id; } else { CrudeModdingStorage.Current.IdentityMessageMap.Add(modName, arg.Id); } await((IUserMessage)arg).PinAsync(); await SaveToDisk(); Console.WriteLine("Mod release/update for" + modName); break; } await Task.CompletedTask; }