I am new to Reddit Bots and wanted to create a bot that could execute Python Commands/Run Saved Functions
I don't write much in Github pages so I don't know how to source much of this but I will try!
The bot will only recognise commands from markdown mode.
Warning! This bot can extract your accounts password! It has moderator access to the bot account as much as you! You will be basically giving access to anyone who tries execute python! Be carefull.. Even the client secret and ID
This BOT uses PRAW and mysql-connector
Every Single Screenshot is from here, here and here
I took the easy route and used regex to search for commands in reddit comments
(\$\!(define|execute)\.function\$\n\:(\w{7,20})\:\n\:\n([\S|\s]+)\n\:\n\$\!(mod|user)\.console\.end\$)

(\$\!(ser|run)\.([\w]{7,20}|all)[\$|\(]([\d|\w| |\,|\']+|)(\)\$|))

The define/execute Function is given priority over search/run Function
Everything other than the explained part is just to add value to the looks and create a syntax which people may not use reguraly and holds no special and meaning/value.
- These commands are only available to the Moderators of a given Subreddit
$!execute.function$
:functionname:
:
def here(x,y):
return x+y
x=5
y=2
z = 10
print(z*here(x,y))
:
$!mod.console.end$$!define.function$
:functionname:
:
def here(x,y):
return x+y
x=5
y=2
z = 10
print(z*here(x,y))
:
$!mod.console.end$Explanation:
$!execute.function$
$!define.function$
- 'execute' helps in identifying the following code is for execution
- Only one restriction don't end with the end...
- 'define' helps in identifying the following code is for saving
- While saving, code will not be executed.
- This function has some restrictions which will be discussed later.
:functionname:
- 'functionname' is the function name that will be stored in the database while saving the code
- This is only useful in define function.
- Function name in database is Unique.
- While it is required in execute function, it is useless as it is not used (Because I am too lazy and am not making it case specific.)
$!mod.console.end$
- In this line 'mod' part can be replace with 'user'
- While this too is required in execute function, it is useless as it is not used (Because I am too lazy and am not making it case specific.)
- In define function however:
- This line defines what the permissions of a saved function should be, when called the code checks if it is allowed to be executed by a 'Normal User' or a 'Moderator.'
$!ser.functi2onname$
$!run.functi2onname(1,5)$
$!run.functi2onname$
- Pretty self explanatory
- For the search function:
- No need for any Input only function name is needed
- Output -> check Output section
- For the run function:
- May or may not need Input
- For knowledge use search function
Everything in that will be shown in the output will be the print function. As seen in the second python file:
- It records every single thing printed and then replies to the comment with that.
- Any error will be reported in the comment if it occurs.
- Everything done is recorded in the second table, This is for bug checking.
- Only confirmation whether the new function has been stored
- Shows the error(outside of the code) if occurs.
- Will not even check whether the code is wrong or not.
In localhost/phpmyadmin/
-
The execute function does not have any restrictions in the general sense
- Just don't use the end phrase anywhere other than at the end (:p)
-
The define function does have other wise it will not work
- Don't use the phrase
^^^INPUT^^^
- Since the define command is not executed upon saving this will not show up an error
- No use of %s formating in functions where input is to be taken! Otherwise it is fine!
- Don't use the phrase
$!run.functioname(1,2)$
- The run function just need to have
- This part is enough to have '([Value],[Value])' for Inputing
- If there are no inputs, Don't put it!













