SayFilters and SayCommands

Discuss API design here.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Nov 06, 2015 7:33 pm

That was an example from a very long time ago when we had implemented say commands/filters in Python. I don't believe we have a way to iterate over them anymore.
Image
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Nov 07, 2015 10:54 am

Yeah, Satoon is right. Though, we can add back that functionality. I will add a feature request to the issue list.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Nov 07, 2015 12:34 pm

I just added generators to iterate over server, client and say commands. https://github.com/Source-Python-Dev-Team/Source.Python/commit/0b73842c20980d230536560c06e7b02676687df0

Example:

Syntax: Select all

from commands.server import ServerCommandGenerator
from commands.client import ClientCommandGenerator
from commands.say import SayCommandGenerator

print('server commands:')
for command in ServerCommandGenerator():
print('\t', command)

print('client commands:')
for command in ClientCommandGenerator():
print('\t', command)

print('say commands:')
for command in SayCommandGenerator():
print('\t', command)
lync
Junior Member
Posts: 3
Joined: Thu Mar 24, 2016 8:10 pm

Postby lync » Thu Mar 24, 2016 8:17 pm

does the @SayCommand have to be in the main plugin file? I have my_plugin.py but I wanted to separate some functionality into its own file that I would import, including a SayCommand function. The plugin loads fine but the functionality isn't working. Any ideas?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Thu Mar 24, 2016 8:21 pm

does the @SayCommand have to be in the main plugin file?

No, it doesn't

The plugin loads fine but the functionality isn't working.

How do you manage to distribute your code across multiple files? That might be the problem. Could you post some code?
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
lync
Junior Member
Posts: 3
Joined: Thu Mar 24, 2016 8:10 pm

Postby lync » Fri Mar 25, 2016 1:59 am

iPlayer wrote:No, it doesn't

The plugin loads fine but the functionality isn't working.

How do you manage to distribute your code across multiple files? That might be the problem. Could you post some code?


Right now I'm just testing stuff but the main gist is I have 2 files in the root directory of the plugin.

1) The main plugin file which sets up the plugin etc and imports the second file called say_test.py

Syntax: Select all

from test_plugin import say_test


2) say_test.py just basically has the saycommand function

Syntax: Select all

from commands.say import SayCommand

@SayCommand(['!help', '!admin'])
def pause_match(command, index, team):
print 'THIS WORKS!'


So yeah its very basic but I just wanted to see if I could make different modules and have the main plugin file be more of just a driver. I am expecting this to print 'THIS WORKS!' to the console when I type !help or !admin in chat. It seems like I have it correct but maybe I am missing something here?
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Fri Mar 25, 2016 2:37 am

Well, we're running Python 3, so I guess the problem is that you're trying to use print as an operator while it's actually a function.
Try this:

Syntax: Select all

print('THIS WORKS!')


Although you should've been getting SyntaxError on that... But anyways, it works for me with parentheses included.

Also, are you sure you're not confusing my_plugin and test_plugin?

You can do

Syntax: Select all

from . import say_test
just to be more flexible.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
lync
Junior Member
Posts: 3
Joined: Thu Mar 24, 2016 8:10 pm

Postby lync » Fri Mar 25, 2016 2:41 am

ok thanks I'll give that a try! I use mainly python 2.X so this is going to be interesting haha

Return to “API Design”

Who is online

Users browsing this forum: No registered users and 20 guests