Skip to content

Commit

Permalink
Small update for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
PSMGoossens committed Jun 16, 2021
1 parent cbdbe38 commit b5de690
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,5 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

ISurvivalBot/config.json
7 changes: 7 additions & 0 deletions ISurvivalBot/Commands/JamaarCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Discord;
using Discord.Commands;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -11,6 +12,11 @@ namespace ISurvivalBot.Commands
public class JamaarCommand : ModuleBase<SocketCommandContext>
{

private readonly ILogger<JamaarCommand> _logger;

public JamaarCommand(ILogger<JamaarCommand> logger) => _logger = logger;



public static Random random = new Random();
public List<String> cards = new List<string>()
Expand Down Expand Up @@ -102,6 +108,7 @@ public class JamaarCommand : ModuleBase<SocketCommandContext>
public async Task Jamaar([Remainder] string text)
{
int answer = random.Next(this.cards.Count);
_logger.LogInformation($"Jamaar Command from: {Context.Message.Author.Username} on channel {Context.Channel.Name}, Question: \"{text}\" Answer: {this.cards[answer]}.");
await Context.Message.ReplyAsync(this.cards[answer]);
}
}
Expand Down
9 changes: 8 additions & 1 deletion ISurvivalBot/Commands/PublicModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Discord;
using Discord.Commands;
using ISurvivalBot.Services;
using ISurvivalBot.Utils;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -89,7 +90,7 @@ public async Task PandaAsync()
[Command("userinfo")]
public async Task UserInfoAsync(IUser user = null)
{
user = user ?? Context.User;
user ??= Context.User;

await ReplyAsync(user.ToString());
}
Expand All @@ -102,6 +103,12 @@ public async Task HowTocommand(string question)
await ReplyAsync($"https://letmegooglethat.com/?q={question}");
}

[Command("berend")]
public async Task BerendCommand()
{
await Context.Message.AddReactionAsync(CommonEmoij.BEREND);
}

// Ban a user
[Command("ban")]
[RequireContext(ContextType.Guild)]
Expand Down
2 changes: 1 addition & 1 deletion ISurvivalBot/Models/BotContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder options)

string path = Path.Combine(Environment.CurrentDirectory, "bot.db");
options.UseSqlite($"Data Source = {path}");
options.UseLoggerFactory(_loggingFactory);
//options.UseLoggerFactory(_loggingFactory);
}

internal void EnqureCreated()
Expand Down
35 changes: 4 additions & 31 deletions ISurvivalBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,40 +91,20 @@ private async Task Client_GuildMembersDownloaded(SocketGuild guild)
{
_logger.LogInformation($"Downloaded Guild {guild.Name} becomes available, with id: {guild.Id}");

/*var usersList = guild.Users.AsEnumerable().Select(o =>
{
Tuple.Create(o.Id, o.Username);
}).ToList();*/

var userList = new List<Tuple<long, string>>();

foreach (var user in guild.Users)
{
userList.Add(Tuple.Create((long)user.Id, user.Username));
}

services.GetRequiredService<UserService>().UpdateUsers(userList);
await services.GetRequiredService<UserService>().UpdateUsers(userList);

/*foreach (var user in guild.Users)
{
_logger.LogInformation($"User id: {user.Id}, Username: {user.Username}");
}*/
}

private async Task Client_GuildAvailable(SocketGuild guild)
{
_logger.LogInformation($"Guild {guild.Name} becomes available, with id: {guild.Id}");

//await guild.DownloadUsersAsync();
/*await foreach (var lst in guild.GetUsersAsync())
{
foreach (var user in lst)
{
_logger.LogInformation($"User id: {user.Id}, Username: {user.Username}");
}
//await services.GetRequiredService<UserService>().UpdateUser((long)user.Id, user.Username);
}*/
}

private async Task updateUsers(DiscordSocketClient client)
Expand All @@ -143,20 +123,20 @@ private async Task updateUsers(DiscordSocketClient client)
{
_logger.LogInformation($"User id: {user.Id}, Username: {user.Username}");
}
//await services.GetRequiredService<UserService>().UpdateUser((long)user.Id, user.Username);
}
}

private async Task Client_UserUpdated(SocketUser old, SocketUser newU)
{
//throw new NotImplementedException();
_logger.LogInformation($"Old user: {old.Username} new user: {newU.Username}, Status: {newU.Status}");
_logger.LogInformation($"User {old.Username} with status {old.Status} becomes user: {newU.Username} new status {newU.Status}");
}

private async Task Client_GuildMemberUpdated(SocketGuildUser old, SocketGuildUser newU)
{
//throw new NotImplementedException();
_logger.LogInformation($"Old user: {old.Username} new user: {newU.Username}, Status: {newU.Status}");
//_logger.LogInformation($"Old user: {old.Username} new user: {newU.Username}, Status: {newU.Status}");
_logger.LogInformation($"User {old.Username} with status {old.Status} becomes user: {newU.Username} new status {newU.Status}");
}

private async Task Client_MessageReceived(SocketMessage message)
Expand Down Expand Up @@ -194,13 +174,6 @@ private int wordDuplication(string text, string word)
return 1;
}

private Task Log(LogMessage msg)
{
_logger.LogInformation(msg.ToString());
return Task.CompletedTask;
}


private Task LogAsync(LogMessage log)
{
_logger.LogInformation(log.ToString());
Expand Down

0 comments on commit b5de690

Please sign in to comment.