Skip to content

Instantly share code, notes, and snippets.

@Joe4evr
Last active March 9, 2018 12:23
Show Gist options
  • Save Joe4evr/6268a10ab217659dddd0a54b11a63051 to your computer and use it in GitHub Desktop.
Save Joe4evr/6268a10ab217659dddd0a54b11a63051 to your computer and use it in GitHub Desktop.
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