Browse Source

Updated the README.md, Added more functionality in the permission system.

master
PHENOMICAL 2 years ago
parent
commit
b155fa2736
4 changed files with 97 additions and 110 deletions
  1. 1
    3
      LICENSE
  2. 21
    11
      Omegle-Discord-Bot/Modules/OmegleModule.cs
  3. 19
    74
      Omegle-Discord-Bot/Modules/OmegleService.cs
  4. 56
    22
      README.md

+ 1
- 3
LICENSE View File

@@ -1,6 +1,4 @@
MIT License

Copyright (c) 2017
Copyright (C) 2017 PHENOMICAL (thephenom1811@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

+ 21
- 11
Omegle-Discord-Bot/Modules/OmegleModule.cs View File

@@ -15,9 +15,21 @@ namespace Omegle_Discord_Bot.Modules
{
public async override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services)
{
await context.Channel.SendMessageAsync("CheckPermissions(...) not implemented!");
return PreconditionResult.FromError("Not implemented!");
}

protected bool isOverridePermissionHolder(ICommandContext context)
{
if (context.User.Id == context.Guild.OwnerId) return true;
if (context.User is SocketGuildUser)
{
SocketGuildUser user = context.User as SocketGuildUser;
if (user.GuildPermissions.Administrator) return true;
}
return false;
}

protected async Task<Permission> readMatchingPermission(ICommandContext context, Database database)
{
IEnumerable<Permission> matchedPermissions = null;
@@ -52,8 +64,6 @@ namespace Omegle_Discord_Bot.Modules
}
public class RequireAtleastRolePermission : PermissionReader
{
Database database;
IServiceProvider provider;
Permission.UserPriviligeEnum userPrivilege;

public RequireAtleastRolePermission(Permission.UserPriviligeEnum userPrivilege)
@@ -63,8 +73,8 @@ namespace Omegle_Discord_Bot.Modules

public async override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services)
{
provider = services;
database = provider.GetService<Database>();
Database database = services.GetService<Database>();
if (isOverridePermissionHolder(context)) return PreconditionResult.FromSuccess();

Permission permission = await readMatchingPermission(context, database);
if (permission != null)
@@ -75,7 +85,7 @@ namespace Omegle_Discord_Bot.Modules
}
else
{
return PreconditionResult.FromError("You need to be atleast in an " + userPrivilege.ToString() + " Administrator Role to execute this command!");
return PreconditionResult.FromError("You need to be atleast in an " + userPrivilege.ToString() + " Role to execute this command!");
}
}
return PreconditionResult.FromError("Permission Error! Not even an everyone role found.");
@@ -84,8 +94,6 @@ namespace Omegle_Discord_Bot.Modules

public class RequirePermission : PermissionReader
{
Database database;
IServiceProvider provider;
Permission.CommandPermissionEnum commandPermission;

public RequirePermission(Permission.CommandPermissionEnum commandPermission)
@@ -95,8 +103,9 @@ namespace Omegle_Discord_Bot.Modules

public async override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services)
{
provider = services;
database = provider.GetService<Database>();
Database database = services.GetService<Database>();
if (isOverridePermissionHolder(context)) return PreconditionResult.FromSuccess();

PreconditionResult result = PreconditionResult.FromError("Precondition Result error!");

Permission permission = await readMatchingPermission(context, database);
@@ -249,13 +258,14 @@ namespace Omegle_Discord_Bot.Modules
}

[Command("setsessiontimeout"), Summary("After a stranger has disconnected from the session, how long should the session remain to exist for")]
[RequireAtleastRolePermission(Permission.UserPriviligeEnum.Administrator)]
public async Task SetSessionTimeout([Summary("Timeout in seconds")] uint timeoutSec)
{
await service.setMaxSessionTimeoutSec(Context, timeoutSec);
await ReplyAsync("Session Timeout has been set to: " + timeoutSec + "s!");
}

[Command("setmaxsessions"), Summary("Limits the amount of sessions on a guild.")]
[RequireAtleastRolePermission(Permission.UserPriviligeEnum.Administrator)]
public async Task SetMaxSessions([Summary("The max amount of guilds that can exist")] byte maxSessions)
{
await service.setMaxSessions(Context, maxSessions);
@@ -339,7 +349,7 @@ namespace Omegle_Discord_Bot.Modules

[Command("set"), Summary("Sets an permission attribute")]
[RequireAtleastRolePermission(Permission.UserPriviligeEnum.Administrator)]
public async Task setRolePermissionAttribute(uint selection, bool val)
public async Task setRolePermissionAttribute([Summary("The @role")] IRole role, uint index, bool val)
{
//await service.addRolePermission(role, Context);
}

+ 19
- 74
Omegle-Discord-Bot/Modules/OmegleService.cs View File

@@ -36,7 +36,7 @@ namespace Omegle_Discord_Bot.Modules
private async Task createGuildConfig(SocketGuild guild)
{
GuildConfig existingConfig = await GuildConfig.readByGuildId(database.connection, guild.Id);
//Is Guild already registered?
if (existingConfig == null)
{
@@ -72,8 +72,8 @@ namespace Omegle_Discord_Bot.Modules
public async Task startChatSession(ShardedCommandContext context, string lang = "en", bool unmoderated = false, string[] topics = null)
{
//Before check if that user already got a conversation running
GuildConfig guildconfig=await GuildConfig.readByGuildId(database.connection, context.Guild.Id);
List<Session> sessionList=await Session.readAllByGuildId(database.connection, context.Guild.Id);
GuildConfig guildconfig = await GuildConfig.readByGuildId(database.connection, context.Guild.Id);
List<Session> sessionList = await Session.readAllByGuildId(database.connection, context.Guild.Id);
Session activeSession = await Session.readByClientId(database.connection, context.User.Id);

if (activeSession != null)
@@ -95,7 +95,7 @@ namespace Omegle_Discord_Bot.Modules
ITextChannel channel = await context.Guild.CreateTextChannelAsync(channelName);
await context.Channel.SendMessageAsync("<@!" + context.User.Id + "> created an Omegle Chat session! Channel: <#" + channel.Id + ">");
OmegleSession session = new OmegleSession(context.User, channel, this);
await session.begin((int) guildconfig.sessionTimeout);
await session.begin((int)guildconfig.sessionTimeout);

client.MessageReceived += session.MessageReceived;
await session.startSession(lang, unmoderated, topics);
@@ -128,75 +128,20 @@ namespace Omegle_Discord_Bot.Modules

}


public async Task<Permission> getPermission(ShardedCommandContext context)
{
Permission finalPermission = null; //Returned Permission
if (context.User is SocketGuildUser && !context.User.IsBot) //Make Sure that the User is on a guild and is not a bot
{
SocketGuildUser guildUser = context.User as SocketGuildUser;

IReadOnlyCollection<SocketRole> userRolesEnum = guildUser.Roles; //Get User Roles
List<ulong> roleIdList = new List<ulong>(); //Stores Role ID's of User
List<Permission> guildPermissionList = await Permission.readAllByGuildId(database.connection, context.Guild.Id); //Holds all permissions that are on this guild

foreach (SocketRole role in userRolesEnum)
{
roleIdList.Add(role.Id);
}


IEnumerable<Permission> matchedPermissions = guildPermissionList.Where(permission => roleIdList.Contains(permission.roleId)); //Identify which Permission matches Role ID's

finalPermission = new Permission();

foreach (Permission permission in matchedPermissions)
{
//Analyze Permission. Hold Permission Attributes that have true as precedence over false
finalPermission.canCreatePrivateSessions |= permission.canCreatePrivateSessions;
finalPermission.canCreatePublicSessions |= permission.canCreatePrivateSessions;
finalPermission.canParticipatePublicSession |= permission.canParticipatePublicSession;
finalPermission.userPrivilege = (Permission.UserPriviligeEnum) Math.Max((byte) finalPermission.userPrivilege, (byte) permission.userPrivilege);
finalPermission.canViewPublicSessions |= permission.canViewPublicSessions;
}

}
return finalPermission;

}

public async Task setMaxSessionTimeoutSec(ShardedCommandContext context, uint timeoutSec)
{
//Check permissions
Permission perm = await getPermission(context);
if(perm.userPrivilege == (Permission.UserPriviligeEnum.Moderator) || perm.userPrivilege == Permission.UserPriviligeEnum.Administrator || context.User.Id == context.Guild.OwnerId)
{
GuildConfig config=await GuildConfig.readByGuildId(database.connection, context.Guild.Id);
config.sessionTimeout = (ushort) timeoutSec;
await config.update(database.connection);
}
else
{
await context.Channel.SendMessageAsync("You have no permission!");
}
GuildConfig config = await GuildConfig.readByGuildId(database.connection, context.Guild.Id);
config.sessionTimeout = (ushort)timeoutSec;
await config.update(database.connection);
await context.Channel.SendMessageAsync("Session Timeout has been set to " + timeoutSec.ToString() + " seconds!");
}

public async Task setMaxSessions(ShardedCommandContext context, uint maxSessions)
{
//Check permissions
Permission perm = await getPermission(context);
if (perm.userPrivilege == (Permission.UserPriviligeEnum.Moderator) || perm.userPrivilege == Permission.UserPriviligeEnum.Administrator /*|| context.User.Id == context.Guild.OwnerId*/)
{
GuildConfig config = await GuildConfig.readByGuildId(database.connection, context.Guild.Id);
config.sessionTimeout = (ushort)maxSessions;
await config.update(database.connection);
await context.Channel.SendMessageAsync("Session limit has been set to " + maxSessions.ToString() + " sessions!");
}
else
{
await context.Channel.SendMessageAsync("You have no permission!");
}
GuildConfig config = await GuildConfig.readByGuildId(database.connection, context.Guild.Id);
config.sessionTimeout = (ushort)maxSessions;
await config.update(database.connection);
await context.Channel.SendMessageAsync("Session limit has been set to " + maxSessions.ToString() + " sessions!");
}

protected EmbedBuilder buildPermssionCard(Permission permission)
@@ -214,7 +159,7 @@ namespace Omegle_Discord_Bot.Modules
embeddedBuilder.WithColor(client.GetGuild(permission.guildId).GetRole(permission.roleId).Color);
embeddedBuilder.WithDescription("Permission entry");
embeddedBuilder.WithThumbnailUrl(client.GetUser(permission.createdByClientID).GetAvatarUrl());
return embeddedBuilder;
}

@@ -222,7 +167,7 @@ namespace Omegle_Discord_Bot.Modules
{
EmbedBuilder embeddedBuilder = new EmbedBuilder();

foreach(Permission permission in permList)
foreach (Permission permission in permList)
{
embeddedBuilder.AddInlineField("Assigned role", "<@&" + permission.roleId + ">");
embeddedBuilder.AddInlineField("Created By", "<@" + permission.createdByClientID + ">");
@@ -236,7 +181,7 @@ namespace Omegle_Discord_Bot.Modules
}
public async Task listGuildPermissions(ShardedCommandContext context)
{
List<Permission> permList= await Permission.readAllByGuildId(database.connection, context.Guild.Id);
List<Permission> permList = await Permission.readAllByGuildId(database.connection, context.Guild.Id);
EmbedBuilder embeddedBuilder = buildSmallPermissionsCard(permList);
await context.Channel.SendMessageAsync("", false, embeddedBuilder.Build());
}
@@ -244,7 +189,7 @@ namespace Omegle_Discord_Bot.Modules
public async Task listPermissionByRoleId(ShardedCommandContext context, ulong roleId)
{
Permission permission = await Permission.readByRoleId(database.connection, roleId);
if(permission.roleId!=0)
if (permission.roleId != 0)
{
EmbedBuilder embeddedBuilder = buildPermssionCard(permission);
await context.Channel.SendMessageAsync("", false, embeddedBuilder.Build());
@@ -257,7 +202,7 @@ namespace Omegle_Discord_Bot.Modules

public async Task addRolePermission(IRole role, ShardedCommandContext context)
{
if(context.Guild.Id != role.Id)
if (context.Guild.Id != role.Id)
{
Permission perm = new Permission();
perm.roleId = role.Id;
@@ -335,9 +280,9 @@ namespace Omegle_Discord_Bot.Modules

public async Task setRoleRight(ShardedCommandContext context, IRole role, Permission.UserPriviligeEnum targetRoleRight)
{
Permission permission=await Permission.readByRoleId(database.connection, role.Id);
Permission permission = await Permission.readByRoleId(database.connection, role.Id);
permission.userPrivilege = targetRoleRight;
if(await permission.update(database.connection))
if (await permission.update(database.connection))
{
await context.Channel.SendMessageAsync("Permission role right set to " + targetRoleRight.ToString());
}

+ 56
- 22
README.md View File

@@ -3,53 +3,87 @@

This is a Discord Bot written in C# that connects to Omegle and utilize the normal chat, question and spyee function.
***
### Current functional Commands
- .omg chat
- .omg end
- .omg reconnect
- .omg admin clean
- .omg admin setsessiontimeout
- .omg admin setmaxsessions
- .omg admin listsessions
## Current functional Commands
- .omg perm list [@role]
- .omg perm add @role
- .omg perm remove @role
- .omg perm setroleright User/Moderator/Administrator
- .omg admin clean (No database support yet, it just deletes all channels starting with omeglechat)
- .omg admin setsessiontimeout NUMTimeSeconds
- .omg admin setmaxsessions NUMMaxChannels
***
### Planned Commands and description
## Normal Chat Commands
## Configuration Setup
<dt>After starting the bot, you must setup the config.json file. That you can find under Omegle-Discord-Bot/bin/{Debug_Or_Release}/netcoreapp1.1/</dt>
<p></p>
<dt>In "Owners" you enter your Client ID and seperate it by commas if you want to add more than just one owner</dt>
<dt>In "Token" you enter your App Bot User Token</dt>
<dt>In "BotClientID" you enter the Bot Client ID</dt>
<dt>In "MySQL_Host" you enter the Host Address for your MySQL Database</dt>
<dt>In "MySQL_User" you enter your MySQL User Handle</dt>
<dt>In "MySQL_Password" you enter your MySQL Password for the User Handle</dt>
<dt>In "MySQL_Database" you can enter a custom Database name that is being used on your MySQL Server</dt>

***
## Planned Commands and description
### Normal Chat Commands
|Command|Example Usage|Description|
|-|:-:|:-:|
|.omg chat [lang] [BOOLunmoderated] [topic1] [topic2]..|.omg chat en false swimming friends|Starts a public Omegle Chat. You wil be moved in a newly created Omegle Channel.|
|.omg chatp [lang] [BOOLunmoderated] [topic1] [topic2]..|.omg chat en false swimming friends|Starts a private Omegle Chat via Direct Messaging|
***

## Ask Question Commands
### Ask Question Commands
|Command|Example Usage|Description|
|-|:-:|:-:|
|.omg question [question]|.omg question How is the weather over there?|Starts a public question chat where you can 2 Strangers discuss your question. You wil be moved in a newly created Omegle Channel.|
|.omg questionp [question]|.omg questionp How is the weather over there?|Starts a private question chat where you can 2 Strangers discuss your question via Direct Messaging.|
|.omg question question|.omg question How is the weather over there?|Starts a public question chat where you can 2 Strangers discuss your question. You wil be moved in a newly created Omegle Channel.|
|.omg questionp question|.omg questionp How is the weather over there?|Starts a private question chat where you can 2 Strangers discuss your question via Direct Messaging.|
***

## Spyee Commands
### Spyee Commands
|Command|Example Usage|Description|
|-|:-:|:-:|
|.omg spyee|.omg spyee|Starts a public Spyee chat where you and others can discuss a question. You wil be moved in a newly created Omegle Channel.|
|.omg spyeep|.omg spyeep|Starts a private Spyee chat via direct messaging.|
***

## General Commands
### General Commands
|Command|Example Usage|Description|
|-|:-:|:-:|
|.omg end|.omg end|Ends your omegle session completely.|
|.omg reconnect|.omg reconnect|Reconnects you with other Stranger/s. Works also in direct messaging.|
***

## Admin Commands
### Admin Commands
### Require Bot owner, Guild owner, Admin role permission, or Permission with Administrator privilege
|Command|Example Usage|Description|
|-|:-:|:-:|
|.omg admin clean|.omg admin clean|Ends all Omegle sessions of your guild and removes the corresponding channels.|
|.omg admin listsesions|.omg admin listsessions|Lists all active sessions.|
|.omg admin endsession @User|.omg admin endsession @PHENOMICAL|Ends the session for the specified user.|
|.omg admin setsessiontimeout NUMTimeSeconds|.omg admin setsessiontimeout 30|After a stranger has disconnected, how long should the channel exist for reconnecting.|
|.omg admin setmaxsessions NUMMaxChannels|.omg admin setmaxsessions 10|Limits how many public chatrooms (Text channels) can be created. Set to 0 for infinite channels.|
|.omg admin setmode Chat/Question/Spyee BOOLEnabled|.omg admin setmode Question false|Determines wether certain modes can be used.|
|.omg admin setreconnectcooldown NUMTimeMilliSeconds|.omg admin setreconnectcooldown 1000|Determines how fast can a user reconnect. I suggest to leave this at >1000ms otherwise this bot may get's IP Banned.|
|.omg admin enablelogging BOOLEnabled|.omg admin enablelogging true|Enables writing a omeglebot_<DATE_TIME>.log|
|.omg admin setsessioncooldown NUMTimeSeconds|.omg admin setsessioncooldown 60| After a user has killed his session, how long does he need to wait before he can start a new one.|
***

### Moderator Commands
### Require Bot owner, Guild owner, Admin role permission, or Permission with atleast Moderator privilege
|Command|Example Usage|Description|
|-|:-:|:-:|
|.omg mod list [@user]|.omg mod list @PHENOMICAL| If @user is supplied, it lists information on that specific session, if not it lists all active sessions.|
|.omg mod endsession @user|.omg admin endsession @PHENOMICAL|Ends the session for the specified user.|
***

### Permission Commands
### Require Bot owner, Guild owner, Admin role permission, or Permission with Administrator privilege
|Command|Example Usage|Description|
|-|:-:|:-:|
|.omg perm list [@role]|.omg perm list @adminRole|[@role] Parameter is optional, but when given it lists the permissions on that role (use this when you want to know which permissions specifically are enabled to that role), otherwise it lists all permissions for your guild in a list style|
|.omg perm remove @role|.omg perm remove @adminRole| Removes a role from the permission system.|
|.omg perm add @role|.omg perm add @adminRole| Adds an role to the permission system.|
|.omg perm set @role NUMindex BOOLValue|.omg perm set @userRole 1 true| Set's a permission right.|
|.omg setroleright @role User/Moderator/Administrator|.omg perm setroleright @modRole Moderator| Set's a Role privilege on the permission.|
***

## Utility Commands
### Utility Commands
### Require Bot owner, Guild owner, Admin role permission, or Permission with atleast Moderator privilege
|Command|Example Usage|Description|
|-|:-:|:-:|
|.omg util status|.omg util status|Returns the total connections to Omegle, Ban status, Antinude percent, Spy queue time, Spyee queue time and Timestamp|