Last active
March 9, 2018 12:23
-
-
Save Joe4evr/6268a10ab217659dddd0a54b11a63051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private readonly PrefixService _prefixService = new PrefixService(); | |
//..... | |
private IServiceProvider ConfigureServices() | |
{ | |
var map = new ServiceCollection() | |
.AddSingleton(_prefixService) | |
//.... | |
; | |
return map.BuildServiceProvider(); | |
} | |
private async Task HandleCommand(SocketMessage msg) | |
{ | |
//... | |
var prefix = _prefixService.GetPrefix(guild) ?? "!"; //default prefix | |
if (msg.HasStringPrefix(prefix, ref argPos)) | |
{ | |
//.... | |
} | |
} | |
} | |
public class PrefixService | |
{ | |
private readonly Dictionary<ulong, string> _prefixes = new Dictionary<ulong, string>(); | |
public string GetPrefix(IGuild guild) => _prefixes.TryGetValue(guild.Id, out var p) ? p : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment