100 lines
4.1 KiB
C#
100 lines
4.1 KiB
C#
using Discord;
|
|
using Discord.Commands;
|
|
using Discord.WebSocket;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Sean.Models;
|
|
using Sean.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sean.Modules
|
|
{
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
public class AwardsModule : ModuleBase<SocketCommandContext>
|
|
{
|
|
#region Properties
|
|
public DbService dbService { get; set; }
|
|
#endregion Properties
|
|
|
|
#region Methods
|
|
[Command("blame")]
|
|
[Summary("Blames the user and removes him one point")]
|
|
[Alias("bash")]
|
|
public async Task BlameUserAsync([Summary("The user to blame")] SocketUser user, [Remainder]string commentaire = "")
|
|
{
|
|
await dbService.UpdateScore(user, -1);
|
|
if (user == Context.User)
|
|
await ReplyAsync($"{Context.User.Nick()} aime l'auto-flagellation...");
|
|
else
|
|
await ReplyAsync($"{Context.User.Nick()} a quelque chose contre {user.Nick()}");
|
|
}
|
|
[Command("board")]
|
|
[Summary("Give the leader board")]
|
|
[Alias("top")]
|
|
public async Task BoardAsync([Remainder] string portee = "")
|
|
{
|
|
string duree = string.Empty;
|
|
DateTime depuis;
|
|
switch (portee)
|
|
{
|
|
case "week": duree = "de la semaine"; depuis = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek); break;
|
|
case "month": duree = "du mois"; depuis = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); break;
|
|
case "year": duree = "de l'année"; depuis = new DateTime(DateTime.Now.Year, 1, 1); break;
|
|
case "ever": duree = "de tous les temps"; depuis = DateTime.MinValue; break;
|
|
default: duree = "du jour"; depuis = DateTime.Today; break;
|
|
}
|
|
|
|
EmbedBuilder builder = new EmbedBuilder
|
|
{
|
|
Title = $"Le top des nazes {duree} !",
|
|
ThumbnailUrl = "https://icon-icons.com/descargaimagen.php?id=62269&root=716/PNG/512/&file=Cup_icon-icons.com_62269.png"
|
|
};
|
|
builder.Footer = new EmbedFooterBuilder { Text = "Allez, au boulot, on peut encore faire pire !" };
|
|
int place = 1;
|
|
var liste = await dbService.Scores.Where(s => s.Date >= depuis).GroupBy(s => s.Score).OrderByDescending(s => s.Key).ToListAsync();
|
|
foreach (var groupe in liste)
|
|
{
|
|
string nom = string.Empty;
|
|
if (place == 1) nom += ":first_place: ";
|
|
else if (place == 2) nom += ":second_place: ";
|
|
else if (place == 3) nom += ":third_place: ";
|
|
else if (place == liste.Count) nom += ":poop: ";
|
|
|
|
nom += string.Join(", ", groupe.Select(g => g.Name));
|
|
builder.AddField(nom, groupe.Key, true);
|
|
place++;
|
|
}
|
|
|
|
await ReplyAsync(embed: builder.Build());
|
|
}
|
|
|
|
[Command("great")]
|
|
[Summary("Greats the user and give him one point")]
|
|
[Alias("reward")]
|
|
public async Task GreatUserAsync([Summary("The user to great")] SocketUser user, [Remainder]string commentaire = "")
|
|
{
|
|
if (user != Context.User)
|
|
{
|
|
await dbService.UpdateScore(user, 1);
|
|
await ReplyAsync($"{Context.User.Nick()} fayotte envers {user.Nick()}");
|
|
}
|
|
else
|
|
{
|
|
await dbService.UpdateScore(user, -1);
|
|
await ReplyAsync($"{Context.User.Nick()} voudrait s'auto-congratuler... Désolé, ce sera une punition !");
|
|
|
|
}
|
|
}
|
|
[Command("help")]
|
|
[Summary("Help !")]
|
|
public async Task HelpAsync()
|
|
{
|
|
IDMChannel channel = await Context.User.GetOrCreateDMChannelAsync();
|
|
await channel.SendMessageAsync($"D'après le site wikipedia.fr, Help! est une chanson des Beatles parue en single en juillet 1965, puis utilisée comme chanson-titre de leur cinquième album et du film dont ils sont les vedettes... Oh, tu m'as pris pour l'assistant Google ?");
|
|
}
|
|
#endregion Methods
|
|
}
|
|
} |