~thomas-juberg/bebot/main

« back to all changes in this revision

Viewing changes to Modules/Roll.php

  • Committer: Thomas Juberg
  • Date: 2013-10-28 03:11:16 UTC
  • Revision ID: git-v1:55563839a2071dbee7d3bda0a2f643a0c9c32852
- Fix IntelliJ project files
- Update .gitignore
- Auto reformat code to PSR-1/PSR-2 code formatting (A lot of work will need to be done to implement PSR-0, PSR-1 and PSR-2 fully, but this should take care of the general formatting)

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
        $this->help['command']['flip [item]'] = "Flips a coin and shows the result. You can provide an optional [item] to record what the coin is being flipped for.";
64
64
        $this->help['command']['verify <num>'] = "Shows the result of roll <num>";
65
65
        $this->bot->core("settings")
66
 
            ->create("Roll", "RollTime", 30, "How many seconds must someone wait before they can roll again?", "5;10;20;30;45;60;120;300;600");
 
66
            ->create(
 
67
                "Roll",
 
68
                "RollTime",
 
69
                30,
 
70
                "How many seconds must someone wait before they can roll again?",
 
71
                "5;10;20;30;45;60;120;300;600"
 
72
            );
67
73
    }
68
74
 
69
75
 
73
79
    function command_handler($name, $msg, $origin)
74
80
    {
75
81
        $com = $this->parse_com(
76
 
            $msg, array(
77
 
                "com",
78
 
                "args"
 
82
            $msg,
 
83
            array(
 
84
                 "com",
 
85
                 "args"
79
86
            )
80
87
        );
81
88
        switch ($com['com']) {
82
 
        case 'roll':
83
 
            $args = $this->parse_com(
84
 
                $com['args'], array(
85
 
                    'min',
86
 
                    'max',
87
 
                    'item'
88
 
                )
89
 
            );
90
 
            if (!isset($args['max'])) {
91
 
                $args['max'] = $args['min'];
92
 
                $args['min'] = 1;
93
 
            }
94
 
            if (!isset($args['item'])) {
95
 
                $args['item'] = "";
96
 
            }
97
 
            return ($this->do_roll($name, $args['min'], $args['max'], $args['item']));
98
 
            break;
99
 
        case 'flip':
100
 
            return ($this->do_flip($name, $com['args']));
101
 
            break;
102
 
        case 'verify':
103
 
            return ($this->verify($com['args']));
104
 
            break;
105
 
        case 'default':
106
 
            $this->bot->send_help($name);
 
89
            case 'roll':
 
90
                $args = $this->parse_com(
 
91
                    $com['args'],
 
92
                    array(
 
93
                         'min',
 
94
                         'max',
 
95
                         'item'
 
96
                    )
 
97
                );
 
98
                if (!isset($args['max'])) {
 
99
                    $args['max'] = $args['min'];
 
100
                    $args['min'] = 1;
 
101
                }
 
102
                if (!isset($args['item'])) {
 
103
                    $args['item'] = "";
 
104
                }
 
105
                return ($this->do_roll($name, $args['min'], $args['max'], $args['item']));
 
106
                break;
 
107
            case 'flip':
 
108
                return ($this->do_flip($name, $com['args']));
 
109
                break;
 
110
            case 'verify':
 
111
                return ($this->verify($com['args']));
 
112
                break;
 
113
            case 'default':
 
114
                $this->bot->send_help($name);
107
115
        }
108
116
    }
109
117
 
119
127
        if ($num < 0 || $num > count($this->roll_info)) {
120
128
            $this->error->set("Invalid verification ID");
121
129
            return ($this->error);
122
 
        }
123
 
        else {
 
130
        } else {
124
131
            $roll = $this->roll_info[$num - 1];
125
132
            $name = "##highlight##{$roll['name']}##end##";
126
133
            if (!empty($roll['item'])) {
149
156
    {
150
157
        if (!isset($this->lastroll[$name])
151
158
            || ($this->lastroll[$name] < time() - $this->bot
152
 
                ->core("settings")->get("Roll", "RollTime"))
 
159
                    ->core("settings")->get("Roll", "RollTime"))
153
160
        ) {
154
161
            if (empty($max)) {
155
162
                $this->error->set("You need to specify a maximum value");
175
182
            echo "Debug: " . $tempdebug . $result['result'] . "\n";
176
183
 
177
184
            return ($this->verify(count($this->roll_info)));
178
 
        }
179
 
        else {
 
185
        } else {
180
186
            return "You may only roll once every " . $this->bot
181
187
                ->core("settings")->get("Roll", "RollTime") . " seconds.";
182
188
        }
190
196
    {
191
197
        if (!isset($this->lastroll[$name])
192
198
            || ($this->lastroll[$name] < time() - $this->bot
193
 
                ->core("settings")->get("Roll", "RollTime"))
 
199
                    ->core("settings")->get("Roll", "RollTime"))
194
200
        ) {
195
201
            $result['name'] = $name;
196
202
            $result['time'] = time();
201
207
            $this->lastroll[$name] = time();
202
208
            $this->roll_info[] = $result;
203
209
            return ($this->verify(count($this->roll_info)));
204
 
        }
205
 
        else {
 
210
        } else {
206
211
            return "You may only flip once every " . $this->bot
207
212
                ->core("settings")->get("Roll", "RollTime") . " seconds.";
208
213
        }